k8s原来这么简单(二)安装k8s1.23集群
官方文档:安装 kubeadm 安装条件
- 多台Linux机器 CentOS7
- 2G以上RAM,2个以上CPU
- 集群网络互通,可访问外网
- 关闭防火墙,关闭swap分区
node | IP |
k8s-master | 192.168.43.111 |
k8s-node1 | 192.168.43.112 |
k8s-node2 | 192.168.43.113 |
关闭防火墙
systemctl stop firewalld && systemctl disable firewalld
关闭selinux
sed -i 's/enforcing/disabled/' /etc/selinux/config # 永久 setenforce 0 # 临时
关闭swap
swapoff -a # 临时 vi /etc/fstab # 永久
设置主机名
hostnamectl set-hostname
添加hosts
cat >> /etc/hosts << EOF 192.168.43.111 k8s-master 192.168.43.112 k8s-node1 192.168.43.113 k8s-node2 EOF
允许 iptables 检查桥接流量
cat <
cat <
sudo sysctl --system
安装Docker
yum install wget -y wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo -O /etc/yum.repos.d/docker-ce.repo yum -y install docker-ce systemctl enable docker && systemctl start docker
配置Docker
cat > /etc/docker/daemon.json << EOF { "exec-opts": ["native.cgroupdriver=systemd"], "log-driver": "json-file", "log-opts": { "max-size": "100m" }, "storage-driver": "overlay2", "registry-mirrors": ["https://vydiw6v2.mirror.aliyuncs.com"] } EOF
systemctl restart docker
安装kubeadm,kubelet和kubectl
添加阿里yum源cat > /etc/yum.repos.d/kubernetes.repo << EOF [kubernetes] name=Kubernetes baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64 enabled=1 gpgcheck=0 repo_gpgcheck=0 gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg EOF
sudo yum install -y kubelet-1.23.0 kubeadm-1.23.0 kubectl-1.23.0 --disableexcludes=kubernetes sudo systemctl enable --now kubelet
以下命令在master主机上运行
初始化master
https://kubernetes.io/zh/docs/reference/setup-tools/kubeadm/kubeadm-init/ kubeadm init \ --apiserver-advertise-address=192.168.43.111 \ --image-repository registry.aliyuncs.com/google_containers \ --kubernetes-version v1.23.0 \ --service-cidr=10.96.0.0/12 \ --pod-network-cidr=10.244.0.0/16 \ --ignore-preflight-errors=all vi /etc/profile export KUBECONFIG=/etc/kubernetes/admin.conf source /etc/profile
kubectl get nodes
【k8s原来这么简单(二)安装k8s1.23集群】
以下命令在node主机上运行
加入node 执行master init之后的join命令kubeadm join 192.16...........
重新获取join命令kubeadm token create --print-join-command
master上安装容器网络
https://kubernetes.io/zh/docs/concepts/cluster-administration/networking/#how-to-implement-the-kubernetes-networking-modelwget https://projectcalico.docs.tigera.io/manifests/tigera-operator.yaml --no-check-certificate wget https://projectcalico.docs.tigera.io/manifests/custom-resources.yaml --no-check-certificate
修改pod网络calicoNetworkkubectl create -f tigera-operator.yaml kubectl create -f custom-resources.yaml
验证
kubectl get pods -n kube-system
kubectl get nodes -o wide
测试集群kubectl create deployment nginx --image=nginx kubectl expose deployment nginx --port=80 --type=NodePort kubectl get pod,svc
推荐阅读
- k8s原来这么简单(一)核心组件与工作原理
- Vue|Vue2的核心原理剖析
- 前端面试|【1.1w字】面试常问Javascript 事件循环、同步异步、宏微任务,彻底明白原来这么简单
- Keepalived+HAProxy高可用集群K8S实现
- k8s入门集群组件介绍及概念理解
- k8s监控数据组件Pod自动化进行扩缩容HPA
- 一天内就可以完成把PC网站改为自适应手机!就是这么简单!
- k8s集群Job负载|k8s集群Job负载 支持多个 Pod 可靠的并发执行,如何权衡利弊选择适合的并行计算模式()
- 给你一张知识地图,计算机组成原理应该这么学
- Python|【AI出牌器】第一次见这么“刺激”的斗地主,胜率高的关键因素竟是......