Your Kubernetes control-plane has initialized successfully!
To start using your cluster, you need to run the following as a regular user: # 准备 .kube 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 # 部署pod network方案 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: # 添加worker节点 kubeadm join 10.1.1.20:6443 --token hd3cjk.sk5co35ml64kw2wo \ --discovery-token-ca-cert-hash sha256:05b42f0a81350227d45f7005c6f2dc664f75d70e0b5e5e8dbfb65705425a859c
$ kubeadm token list TOKEN TTL EXPIRES USAGES DESCRIPTION EXTRA GROUPS hd3cjk.sk5co35ml64kw2wo 23h 2023-12-19T03:41:11Z authentication,signing The default bootstrap token generated by 'kubeadm init'. system:bootstrappers:kubeadm:default-node-token
$ kubectl get nodes NAME STATUS ROLES AGE VERSION k8s-master Ready control-plane 7m v1.28.0 k8s-node1 Ready <none> 50s v1.28.0 k8s-node2 Ready <none> 21s v1.28.0
集群验证
创建pod
创建一个nginx的pod,pod能成功过running
1 2 3 4 5
$ kubectl run web --image nginx pod/web created $ kubectl get pods NAME READY STATUS RESTARTS AGE web 1/1 Running 0 5s
$ kubectl expose pod web --port=80 --name=web-service service/web-service exposed $ kubectl get service NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 65m web-service ClusterIP 10.96.95.185 <none> 80/TCP 4s $ curl 10.96.95.185 ... <title>Welcome to nginx!</title> ...
环境清理
1 2
$ kubectl delete service web-service $ kubectl delete pod web