主机名 | 系统版本 | 内核版本 | IP地址 | 备注 |
---|---|---|---|---|
k8s-master-11 | centos7.6.1810 | 5.4.13 | 192.168.1.11 | master节点-worker节点 |
说明:建议操作系统选择centos7.5或centos7.6,centos7.2,centos7.3,centos7.4版本存在一定几率的kubelet无法启动问题。
hostnamectl set-hostname k8s-master-11
《Centos7内核升级至5.4.13一键脚本》
《kubernetes系统环境初始化一键脚本》
《Linux运维实战:Centos7.6一键离线部署docker19.03.9》
cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF
yum clean all && yum -y makecache
# 1、版本查看
yum list kubelet --showduplicates | sort -r
# 2、安装1.17.4版本
yum install kubelet-1.20.6 kubeadm-1.20.6 kubectl-1.20.6 -y
kubernetes-v1.20.6+calio-v3.20.0+calico.yaml完整镜像资源包
镜像版本如下:
k8s.gcr.io/kube-apiserver:v1.20.6
k8s.gcr.io/kube-controller-manager:v1.20.6
k8s.gcr.io/kube-scheduler:v1.20.6
k8s.gcr.io/kube-proxy:v1.20.6
k8s.gcr.io/pause:3.2
k8s.gcr.io/etcd:3.4.13-0
k8s.gcr.io/coredns:1.7.0
calico/pod2daemon-flexvol:v3.20.0
calico/node:v3.20.0
calico/cni:v3.20.0
calico/kube-controllers:v3.20.0
#1、kubernetes配置文件
vim kubeadm-config.yaml
apiVersion: kubeadm.k8s.io/v1beta2
kind: ClusterConfiguration
networking:
serviceSubnet: "10.96.0.0/16"
podSubnet: "10.244.0.0/16"
kubernetesVersion: "v1.20.6"
controlPlaneEndpoint: "192.168.1.11:6443"
apiServer:
extraArgs:
authorization-mode: "Node,RBAC"
service-node-port-range: 30000-36000
imageRepository: ""
---
apiVersion: kubeadm.k8s.io/v1beta2
kind: KubeProxyConfiguration
mode: "ipvs"
#2、kubeadm初始化kubernetes集群
kubeadm init --config=kubeadm-config.yaml --upload-certs --ignore-preflight-errors=SystemVerification
#3、设置kubelet开机自启
systemctl enable kubelet
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
export KUBECONFIG=/etc/kubernetes/admin.conf
#1、下载calico.yaml文件
wget https://docs.projectcalico.org/manifests/calico.yaml
#2、在master节点上部署CNI网络
kubectl apply -f calico.yaml
#3、查看master节点状态
[root@k8s-master-11 kubernete-tools]# kubectl get nodes
NAME STATUS ROLES AGE VERSION
k8s-master-11 Ready control-plane,master 105m v1.20.6
说明:使用kubeadm初始化的kubernetes,出于安全考虑Pod不会被调度到Master Node上,也就是说Master Node不参与工作负载。
#1、查看k8s-master-11节点
[root@k8s-master-11 ~]# kubectl describe node k8s-master-11 | grep Taints
Taints: node-role.kubernetes.io/master:NoSchedule
说明:master:NoSchedule表示当前节点为不可调度节点
#2、将k8s-master-11节点设置可可调度节点
[root@k8s-master-11 ~]# kubectl taint node k8s-master-11 node-role.kubernetes.io/master-
node/k8s-master-11 untainted
[root@k8s-master-11 ~]# kubectl describe node k8s-master-11 | grep Taints
Taints: <none>
#3、其中k8s-master是主机节点hostname如果要恢复Master Only状态,执行如下命令:
[root@k8s-master-11 ~]# kubectl taint node k8s-master-11 node-role.kubernetes.io/master="":NoSchedule
node/k8s-master-11 tainted
[root@k8s-master-11 ~]# kubectl describe node k8s-master-11 | grep Taints
Taints: node-role.kubernetes.io/master:NoSchedule
如下图所示:
至此,单节点kubernetes就部署完成了。
下一章:《Kubernetes部署篇:Centos7.6部署kubernetes1.20.6单master集群》》
更多详细内容请参考:企业级K8s集群运维实战