k8s环境搭建(二)——初始化集群
1. 前言接上一篇文章:https://blog.csdn.net/weixin_29003023/article/details/110409382,不过这篇文章写的不是很好,还需要改善下。本文假定你已经安装docker,kubelet、kubeadm、kubectl。2. 初始化master节点所有机器添加master域名映射。给/etc/hosts文件配置主节点的IP,例如如下:10.206
·
1. 前言
接上一篇文章:https://blog.csdn.net/weixin_29003023/article/details/110409382,不过这篇文章写的不是很好,还需要改善下。
本文假定你已经安装docker,kubelet、kubeadm、kubectl。
2. 初始化master节点
所有机器添加master域名映射。给/etc/hosts文件配置主节点的IP,例如如下:10.206.0.9为主节点的内外IP。
echo "10.206.0.9 cluster-endpoint" >> /etc/hosts
主节点初始化
kubeadm init \
--apiserver-advertise-address=10.206.0.9 \
--control-plane-endpoint=cluster-endpoint \
--image-repository registry.cn-hangzhou.aliyuncs.com/lfy_k8s_images \
--kubernetes-version v1.20.9 \
--service-cidr=10.96.0.0/16 \
--pod-network-cidr=192.168.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/
You can now join any number of control-plane nodes by copying certificate authorities
and service account keys on each node and then running the following as root:
kubeadm join cluster-endpoint:6443 --token zkm0a3.pgvodwj1bn26lj9h \
--discovery-token-ca-cert-hash sha256:85aed272ede53d8a84c75a173c35c44727734c9c29de3e16eaeb1a936bb84546 \
--control-plane
Then you can join any number of worker nodes by running the following on each as root:
kubeadm join cluster-endpoint:6443 --token zkm0a3.pgvodwj1bn26lj9h \
--discovery-token-ca-cert-hash sha256:85aed272ede53d8a84c75a173c35c44727734c9c29de3e16eaeb1a936bb84546
3. 开启主节点
根据上面的初始化结果输出,开启主节点:
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
以上这几条命令,再上面的初始化结果中寻找哈。
查看主节点初始化结果:
[root@VM-0-9-centos ~]# kubectl get nodes
NAME STATUS ROLES AGE VERSION
vm-0-9-centos NotReady control-plane,master 6m4s v1.20.9
[root@VM-0-9-centos ~]#
4. 安装网络插件
安装的是calico这个网络组件。
[root@VM-0-9-centos ~]# curl https://docs.projectcalico.org/manifests/calico.yaml -O
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 212k 100 212k 0 0 2752 0 0:01:19 0:01:19 --:--:-- 4651
[root@VM-0-9-centos ~]# ls
calico.yaml images.sh
[root@VM-0-9-centos ~]# kubectl apply -f calico.yaml
configmap/calico-config created
customresourcedefinition.apiextensions.k8s.io/bgpconfigurations.crd.projectcalico.org created
customresourcedefinition.apiextensions.k8s.io/bgppeers.crd.projectcalico.org created
customresourcedefinition.apiextensions.k8s.io/blockaffinities.crd.projectcalico.org created
customresourcedefinition.apiextensions.k8s.io/caliconodestatuses.crd.projectcalico.org created
customresourcedefinition.apiextensions.k8s.io/clusterinformations.crd.projectcalico.org created
customresourcedefinition.apiextensions.k8s.io/felixconfigurations.crd.projectcalico.org created
customresourcedefinition.apiextensions.k8s.io/globalnetworkpolicies.crd.projectcalico.org created
customresourcedefinition.apiextensions.k8s.io/globalnetworksets.crd.projectcalico.org created
customresourcedefinition.apiextensions.k8s.io/hostendpoints.crd.projectcalico.org created
customresourcedefinition.apiextensions.k8s.io/ipamblocks.crd.projectcalico.org created
customresourcedefinition.apiextensions.k8s.io/ipamconfigs.crd.projectcalico.org created
customresourcedefinition.apiextensions.k8s.io/ipamhandles.crd.projectcalico.org created
customresourcedefinition.apiextensions.k8s.io/ippools.crd.projectcalico.org created
customresourcedefinition.apiextensions.k8s.io/ipreservations.crd.projectcalico.org created
customresourcedefinition.apiextensions.k8s.io/kubecontrollersconfigurations.crd.projectcalico.org created
customresourcedefinition.apiextensions.k8s.io/networkpolicies.crd.projectcalico.org created
customresourcedefinition.apiextensions.k8s.io/networksets.crd.projectcalico.org created
clusterrole.rbac.authorization.k8s.io/calico-kube-controllers created
clusterrolebinding.rbac.authorization.k8s.io/calico-kube-controllers created
clusterrole.rbac.authorization.k8s.io/calico-node created
clusterrolebinding.rbac.authorization.k8s.io/calico-node created
daemonset.apps/calico-node created
serviceaccount/calico-node created
deployment.apps/calico-kube-controllers created
serviceaccount/calico-kube-controllers created
poddisruptionbudget.policy/calico-kube-controllers created
检查主节点状态:
[root@VM-0-9-centos ~]# kubectl get nodes
NAME STATUS ROLES AGE VERSION
vm-0-9-centos Ready control-plane,master 52m v1.20.9
[root@VM-0-9-centos ~]#
5. 加入node节点
kubeadm join cluster-endpoint:6443 --token zkm0a3.pgvodwj1bn26lj9h \
> --discovery-token-ca-cert-hash sha256:85aed272ede53d8a84c75a173c35c44727734c9c29de3e16eaeb1a936bb84546
加入之后,在主节点上查看集群:
更多推荐
已为社区贡献3条内容
所有评论(0)