当我们在master节点、安装部署完docker与Kubernetes / k8s 相关的软件后,并启动(docker,kubelet)后,接下来就是需要对master节点进行初始化操作了
如下,这里笔者使用的版本的为 Kubernetes-v1.23.6,初始化是使用kubeadm init命令,详细的参数如下所示:
注意点:执行前需要先将docker的Cgroup Driver由默认的cgroupfs修改成systemd,并重启docker让配置生效
[root@k8s-master qq-5201351]# kubeadm init \ > --apiserver-advertise-address 192.18.106.87 \ > --image-repository registry.aliyuncs.com/google_containers \ > --kubernetes-version v1.23.6 \ > --service-cidr=10.96.0.0/12 \ > --pod-network-cidr=10.224.0.0/16
如果没有相关的报错,就算是正常了,命令执行完成后,可以看到一段提示
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/.kube sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config sudo chown $(id -u):$(id -g) $HOME/.kube/config Alternatively, if you are the root user, you can run: export KUBECONFIG=/etc/kubernetes/admin.conf You 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 192.18.106.87:6443 --token 8iz44r.cxj5duahe37wsdgq \ --discovery-token-ca-cert-hash sha256:08752ac13ae6f821c44abdf6eb1fa2481777b82d20335e4467829ac20b503e55
根据提示,如果要开始使用k8s cluster,还需要在master节点上执行如下几条命令,这里笔者是使用root用户,所以去掉了sudo,最终命令如下:
mkdir -p $HOME/.kube cp -i /etc/kubernetes/admin.conf $HOME/.kube/config chown $(id -u):$(id -g) $HOME/.kube/config
这样,master节点的初始化,就算是完成了,上面的都执行了,也才可以通过kubectl get nodes命令看到k8s集群中的master节点
其他说明:初始化后,我们可以也可以通过docker命令看出来,拉取了如下7个镜像:
[root@k8s-master ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE registry.aliyuncs.com/google_containers/kube-apiserver v1.23.6 8fa62c12256d 12 months ago 135MB registry.aliyuncs.com/google_containers/kube-scheduler v1.23.6 595f327f224a 12 months ago 53.5MB registry.aliyuncs.com/google_containers/kube-proxy v1.23.6 4c0375452406 12 months ago 112MB registry.aliyuncs.com/google_containers/kube-controller-manager v1.23.6 df7b72818ad2 12 months ago 125MB registry.aliyuncs.com/google_containers/etcd 3.5.1-0 25f8c7f3da61 18 months ago 293MB registry.aliyuncs.com/google_containers/coredns v1.8.6 a4ca41631cc7 19 months ago 46.8MB registry.aliyuncs.com/google_containers/pause 3.6 6270bb605e12 20 months ago 683kB [root@k8s-master ~]#
尊重别人的劳动成果 转载请务必注明出处: https://www.cnblogs.com/5201351/p/17381460.html
作者:一名卑微的IT民工
出处:https://www.cnblogs.com/5201351
本博客所有文章仅用于学习、研究和交流目的,欢迎非商业性质转载。
由于博主的水平不高,文章没有高度、深度和广度,只是凑字数,不足和错误之处在所难免,希望大家能够批评指出。
博主是利用读书、参考、引用、复制和粘贴等多种方式打造成自己的文章,请原谅博主成为一个卑微的IT民工!