1> 部署应用
[root@k8s-master ~]# kubectl run nginx --image=nginx:1.7.9
deployment "nginx" created[root@k8s-master ~]# kubectl get deploy
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
nginx 1 1 1 1 42s
2>查看应用
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE CONTAINERS IMAGES SELECTOR
nginx 1 1 1 1 55s nginx nginx:1.7.9 run=nginx
3> 查看pod具体信息
NAME READY STATUS RESTARTS AGE IP NODE
nginx-665ff4c6f7-q76rg 1/1 Running 0 1m 10.244.1.25 huleib.eng.platformlab.ibm.com
4> 暴露部署服务:
[root@k8s-master ~]# kubectl expose deploy nginx --type=NodePort --name=nginx-test --port=80
service "nginx-test" exposed
[root@k8s-master ~]# kubectl expose deploy nginx --type=NodePort --name=nginx --port=80service "nginx" exposed
5> 验证部署的服务为什么基于同一个pod
NAME ENDPOINTS AGE
kubernetes 9.111.252.196:6443 3d
nginx 10.244.1.25:80 8s
nginx-test 10.244.1.25:80 40s
testa 10.244.1.25:80 3m
[root@k8s-master ~]# kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 3d
nginx NodePort 10.97.73.87 <none> 80:30031/TCP 35s
nginx-test NodePort 10.102.130.239 <none> 80:31098/TCP 1m
testa NodePort 10.111.157.251 <none> 80:30690/TCP 3m
6> 删除服务
[root@k8s-master ~]# kubectl delete svc testa
service "testa" deleted[root@k8s-master ~]# kubectl get ep
NAME ENDPOINTS AGE
kubernetes 9.111.252.196:6443 3d
nginx 10.244.1.25:80 1m
nginx-test 10.244.1.25:80 1m