干干静静的centos7系统,选取的是mini的iso最小化安装
# cat /etc/centos-release CentOS Linux release 7.3.1611 (Core) # cat /proc/version Linux version 3.10.0-514.el7.x86_64 (builder@kbuilder.dev.centos.org) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-11) (GCC) ) #1 SMP Tue Nov 22 16:42:41 UTC 2016
K8S使用的当前(现在是2021-04-07)最新版本:v1.20。官方教程:https://kubernetes.io/zh/docs/home/。安装方式采用kubeadm安装。
最少2个节点,其中1个节点作为master节点,其他节点作为node节点,本例中:
# ssh root@10.10.2.241 # hostnamectl set-hostname k8s-1 # exit # ssh root@10.10.2.242 # hostnamectl set-hostname k8s-2 # exit # ssh root@10.10.2.242 # hostnamectl set-hostname k8s-3 # exit
# setenforce 0 # sed -i 's|SELINUX=\(.*\)|SELINUX=disabled|g' /etc/selinux/config
# curl -o /etc/yum.repos.d/docker-ce.repo https://download.docker.com/linux/centos/docker-ce.repo
# yum install -y docker-ce
# systemctl start docker # systemctl enable docker
# swapoff -a # vim /etc/fstab 将有swap那行注释掉
# vim /etc/yum.repos.d/kubernetes.repo 输入一下内容保存 [kubernetes] name=kubernetes baseurl=https://opentuna.cn/kubernetes/yum/repos/kubernetes-el7-$basearch enabled=1
# yum install -y kubelet kubeadm kubectl --nogpgcheck
# docker pull registry.aliyuncs.com/google_containers/kube-apiserver:v1.20.5 # docker pull registry.aliyuncs.com/google_containers/kube-controller-manager:v1.20.5 # docker pull registry.aliyuncs.com/google_containers/kube-scheduler:v1.20.5 # docker pull registry.aliyuncs.com/google_containers/kube-proxy:v1.20.5 # docker pull registry.aliyuncs.com/google_containers/pause:3.2 # docker pull registry.aliyuncs.com/google_containers/etcd:3.4.13-0 # docker pull registry.aliyuncs.com/google_containers/coredns:1.7.0 # docker tag registry.aliyuncs.com/google_containers/kube-apiserver:v1.20.5 k8s.gcr.io/kube-apiserver:v1.20.5 # docker tag registry.aliyuncs.com/google_containers/kube-controller-manager:v1.20.5 k8s.gcr.io/kube-controller-manager:v1.20.5 # docker tag registry.aliyuncs.com/google_containers/kube-scheduler:v1.20.5 k8s.gcr.io/kube-scheduler:v1.20.5 # docker tag registry.aliyuncs.com/google_containers/kube-proxy:v1.20.5 k8s.gcr.io/kube-proxy:v1.20.5 # docker tag registry.aliyuncs.com/google_containers/pause:3.2 k8s.gcr.io/pause:3.2 # docker tag registry.aliyuncs.com/google_containers/etcd:3.4.13-0 k8s.gcr.io/etcd:3.4.13-0 # docker tag registry.aliyuncs.com/google_containers/coredns:1.7.0 k8s.gcr.io/coredns:1.7.0
# kubeadm init
注意执行成功后类似如下输出,复制下来
kubeadm join 10.10.2.241:6443 --token 2dhvds.4yd881szk64kqxoo --discovery-token-ca-cert-hash sha256:5435c5cbfbef0e00f5fd7b96c325771adc5a8f5591a7799939861bde6d0f557f
# export KUBECONFIG=/etc/kubernetes/admin.conf
# kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
执行2.9步输出内容
# ssh root@10.10.2.242 # kubeadm join 10.10.2.241:6443 --token 2dhvds.4yd881szk64kqxoo --discovery-token-ca-cert-hash sha256:5435c5cbfbef0e00f5fd7b96c325771adc5a8f5591a7799939861bde6d0f557f # exit # ssh root@10.10.2.243 # kubeadm join 10.10.2.241:6443 --token 2dhvds.4yd881szk64kqxoo --discovery-token-ca-cert-hash sha256:5435c5cbfbef0e00f5fd7b96c325771adc5a8f5591a7799939861bde6d0f557f # exit
# kubectl get nodes NAME STATUS ROLES AGE VERSION k8s-1 Ready control-plane,master 171m v1.20.5 k8s-2 Ready <none> 6m48s v1.20.5 k8s-3 Ready <none> 7m35s v1.20.5