Kubeadm部署Kubernetes( 二 )

#master上执行(10.0.0.101):# 在运行 kubeadm init 之前先执行 kubeadm config images pull 来测试与 gcr.io 的连接,kubeadm config images pull尝试是否可以拉取镜像,如果你的服务器再国内,由于某些原因,是无法访问"k8s.gcr.io", "gcr.io", "quay.io"[root@k8s-master ~]#kubeadm config images list#查看kubeadm config 依赖的images有哪些#执行结果如下k8s.gcr.io/kube-apiserver:v1.23.8k8s.gcr.io/kube-controller-manager:v1.23.8k8s.gcr.io/kube-scheduler:v1.23.8k8s.gcr.io/kube-proxy:v1.23.8k8s.gcr.io/pause:3.6k8s.gcr.io/etcd:3.5.1-0k8s.gcr.io/coredns/coredns:v1.8.6#从国内镜像拉取[root@master ~]#docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-apiserver:v1.23.8[root@master ~]#docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-controller-manager:v1.23.8[root@master ~]#docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-scheduler:v1.23.8[root@master ~]#docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-proxy:v1.23.8[root@master ~]#docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.6[root@master ~]#docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/etcd:3.5.1-0[root@master ~]#docker pull coredns/coredns:1.8.6#或者拉取最新版,一条命令如下:[root@k8s-master ~]#kubeadm config images pull --image-repository=registry.aliyuncs.com/google_containers#拉取镜像#master上执行(10.0.0.101):#将拉取下来的images重命名为kubeadm config所需的镜像名字#注意版本号有的是带v的,有的不带的v[root@master ~]#docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/kube-apiserver:v1.23.8 k8s.gcr.io/kube-apiserver:v1.23.8[root@master ~]#docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/kube-controller-manager:v1.23.8 k8s.gcr.io/kube-controller-manager:v1.23.8[root@master ~]#docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/kube-scheduler:v1.23.8 k8s.gcr.io/kube-scheduler:v1.23.8[root@master ~]#docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/kube-proxy:v1.23.8 k8s.gcr.io/kube-proxy:v1.23.8[root@master ~]#docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.6 k8s.gcr.io/pause:3.6[root@master ~]#docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/etcd:3.5.1-0 k8s.gcr.io/etcd:3.5.1-0[root@master ~]#docker tag coredns/coredns:1.8.6 k8s.gcr.io/coredns/coredns:v1.8.6#master上执行(10.0.0.101):#初始化[root@master ~]#kubeadm init --config kubeadm-config.yaml#如果提示以下信息,安装成功,如果安装失败,请卸载kubectl、kubeadm、kubelet 然后再重新执行Your Kubernetes control-plane has initialized successfully!To start using your cluster, you need to run the following as a regular user:mkdir -p $HOME/.kubesudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/configsudo chown $(id -u):$(id -g) $HOME/.kube/configAlternatively, if you are the root user, you can run:export KUBECONFIG=/etc/kubernetes/admin.confYou should now deploy a pod network to the cluster.Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:https://kubernetes.io/docs/concepts/cluster-administration/addons/Then you can join any number of worker nodes by running the following on each as root:kubeadm join 10.0.0.101:6443 --token abcdef.0123456789abcdef \ --discovery-token-ca-cert-hash sha256:415922bb8c4fd6768756559cdabc18bacc8661c86ebd411be9e6cd1036041c09 #记住上边的node加入集群的命令,如果忘记,可以使用如下命令获取:kubeadm token create --print-join-command

Kubeadm部署Kubernetes

文章插图
4、部署node节点#所有node节点执行:#请确保基础环境已经部署好(时间同步,防火墙,解析,swap,内核参数)[root@node ~]#apt-get install -y ca-certificates curl software-properties-common apt-transport-https curl[root@node ~]#apt-get update && apt-get install -y apt-transport-https[root@node ~]#curl https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | apt-key add -[root@node ~]# cat <<EOF >/etc/apt/sources.list.d/kubernetes.listdeb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial mainEOF[root@node ~]#apt update[root@node ~]#apt install -y kubelet=1.23.1-00 kubeadm=1.23.1-00 kubectl=1.23.1-00[root@node2 ~]#apt-mark hold kubelet kubeadm kubectl

经验总结扩展阅读