环境:已安装完成Kubernetes
master节点192.168.1.10/centos7
node节点 192.168.1.11/centos7
1.创建部署deployment
--image镜像来自docker
[root@master ~]# kubectl create deployment test-nginx --image=nginx deployment.apps/test-nginx created
2.查询验证deployment
查看deployment列表
[root@master ~]# kubectl get deployment NAME READY UP-TO-DATE AVAILABLE AGE test-nginx 0/1 1 0 31s
查看pod运行列表
[root@master ~]# kubectl get pods NAME READY STATUS RESTARTS AGE test-nginx-64759dd789-vw48m 1/1 Running 0 119s
3.发布服务
暴露80端口方式发布服务
[root@master ~]# kubectl expose deployment test-nginx --port=80 --type=NodePort service/test-nginx exposed
或者
[root@master ~]# kubectl create service nodeport test-nginx --tcp 80 service/test-nginx created
查询端口,此处test-nginx服务暴露为30627
4.访问测试
通过master节点访问
通过node节点访问
5.pod容器伸缩
通过kubectl scale调整容器副本数量,--replicas参数实现增加或减少集群副本数量
[root@master ~]# kubectl scale deployment test-nginx --replicas=5 deployment.extensions/test-nginx scaled
再次查询pod时test-nginx副本已经增加到5个
6.删除部署和服务
[root@master ~]# kubectl delete services test-nginx service "test-nginx" deleted [root@master ~]# kubectl delete deployment test-nginx deployment.extensions "test-nginx" deleted
或者
[root@master ~]# kubectl delete deployments/test-nginx services/test-nginx deployment.extensions "test-nginx" deleted service "test-nginx" deleted