$sudo kubeadm init \
--image-repository=registry.aliyuncs.com/google_containers \
--control-plane-endpoint k8s-api.maxidea.com \
--apiserver-advertise-address 192.168.2.31 \
--pod-network-cidr 10.244.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
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 k8s-api.maxidea.com:6443 --token q9de5i.toeqluiwv9ij99o2 \
--discovery-token-ca-cert-hash sha256:2556bfaa0cb5a99771867b310eb00f38736736da33289d040a4e88c36d7d81af \
--control-plane
Then you can join any number of worker nodes by running the following on each as root:
kubeadm join k8s-api.maxidea.com:6443 --token q9de5i.toeqluiwv9ij99o2 \
--discovery-token-ca-cert-hash sha256:2556bfaa0cb5a99771867b310eb00f38736736da33289d040a4e88c36d7d81af
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Starting 37m kubelet, 31 Starting kubelet.
Normal NodeHasSufficientMemory 37m kubelet, 31 Node 31 status is now: NodeHasSufficientMemory
Normal NodeHasNoDiskPressure 37m kubelet, 31 Node 31 status is now: NodeHasNoDiskPressure
Normal NodeHasSufficientPID 37m kubelet, 31 Node 31 status is now: NodeHasSufficientPID
Normal NodeAllocatableEnforced 37m kubelet, 31 Updated Node Allocatable limit across pods
Normal Starting 37m kube-proxy, 31 Starting kube-proxy.
$ kubectl apply -f https://gitee.com/maxidea/flannel/raw/master/Documentation/kube-flannel.yml
podsecuritypolicy.policy/psp.flannel.unprivileged created
clusterrole.rbac.authorization.k8s.io/flannel created
clusterrolebinding.rbac.authorization.k8s.io/flannel created
serviceaccount/flannel created
configmap/kube-flannel-cfg created
daemonset.apps/kube-flannel-ds-amd64 created
daemonset.apps/kube-flannel-ds-arm64 created
daemonset.apps/kube-flannel-ds-arm created
daemonset.apps/kube-flannel-ds-ppc64le created
daemonset.apps/kube-flannel-ds-s390x created
Then you can join any number of worker nodes by running the following on each as root:
kubeadm join k8s-api.maxidea.com:6443 --token q9de5i.toeqluiwv9ij99o2 \
--discovery-token-ca-cert-hash sha256:2556bfaa0cb5a99771867b310eb00f38736736da33289d040a4e88c36d7d81af
# kubeadm join k8s-api.maxidea.com:6443 --token qizy9v.32fin79ao8ekgrip --discovery-token-ca-cert-hash sha256:2556bfaa0cb5a99771867b310eb00f38736736da33289d040a4e88c36d7d81af
W0520 20:59:08.784524 4146 join.go:346] [preflight] WARNING: JoinControlPane.controlPlane settings will be ignored when control-plane flag is not set.
[preflight] Running pre-flight checks
[preflight] Reading configuration from the cluster...
[preflight] FYI: You can look at this config file with 'kubectl -n kube-system get cm kubeadm-config -oyaml'
[kubelet-start] Downloading configuration for the kubelet from the "kubelet-config-1.18" ConfigMap in the kube-system namespace
[kubelet-start] Writing kubelet configuration to file "/var/lib/kubelet/config.yaml"
[kubelet-start] Writing kubelet environment file with flags to file "/var/lib/kubelet/kubeadm-flags.env"
[kubelet-start] Starting the kubelet
[kubelet-start] Waiting for the kubelet to perform the TLS Bootstrap...
This node has joined the cluster:
* Certificate signing request was sent to apiserver and a response was received.
* The Kubelet was informed of the new secure connection details.
Run 'kubectl get nodes' on the control-plane to see this node join the cluster.
大约10~30秒后,节点上的pod启动完毕,在控制平面上再次运行kubectl get nodes,就可以看到各工作节点已经加入了:
$ kubectl get nodes
NAME STATUS ROLES AGE VERSION
31 Ready master 29h v1.18.2
35 Ready <none> 4m56s v1.18.2
36 Ready <none> 53s v1.18.2
37 Ready <none> 43s v1.18.2
# kubeadm init phase upload-certs --upload-certs
W0521 00:32:26.439917 753 configset.go:202] WARNING: kubeadm cannot validate component configs for API groups [kubelet.config.k8s.io kubeproxy.config.k8s.io]
[upload-certs] Storing the certificates in Secret "kubeadm-certs" in the "kube-system" Namespace
[upload-certs] Using certificate key:
76ac4d6f4ab459cd57bbb1ba874d7b6eae188116fcb0089eca621fcdad0ed490
完成后使用普通用户运行kubectl get secret -n kube-system命令查看。
2)其他主节点加入到集群
完成证书复制后,可以开始把其他主节点加入成为控制平面,如2-2初始化第一个控制平面时,获得的提示:
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 k8s-api.maxidea.com:6443 --token q9de5i.toeqluiwv9ij99o2 \
--discovery-token-ca-cert-hash sha256:2556bfaa0cb5a99771867b310eb00f38736736da33289d040a4e88c36d7d81af \
--control-plane