更新时间:2022-05-12 GMT+08:00
运行与验证
验证K8s集群的部署结果
本章节以部署Nginx服务为例。
- 在管理节点中创建一个名为nginx_deploy.yaml的文件,在其中添加如下内容。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
apiVersion: apps/v1beta1 kind: Deployment metadata: name: nginx-deployment spec: replicas: 2 # tells deployment to run 2 pods matching the template template: # create pods using pod definition in this template metadata: # unlike pod-nginx.yaml, the name is not included in the meta data as a unique name is # generated from the deployment name labels: app: nginx spec: containers: - name: nginx image: nginx ports: - containerPort: 80
- 创建完毕后执行如下命令,部署节点。
1
kubectl create -f nginx_deploy.yaml
- 执行pod命令,查看K8s创建这个deployment的过程。
1
kubectl get pod --all-namespaces -o wide
执行结果如图1所示,可以看到有两个新的属于nginx-deployment的pod正在被创建。
删除集群(谨慎操作)
如果不需要使用K8s集群时,可以按本章节操作,删除K8s集群。
- 在集群的管理节点上执行如下命令,清除集群设置。
1
kubeadm reset
- 在集群内所有计算节点上执行如下命令,删除整个集群。
1
kubeadm reset
父主题: 手动部署
