# curl 10.244.3.2 <!DOCTYPE html> <html> <head> <title>Welcome to nginx!</title> <style> body { width: 35em; margin: 0 auto; font-family: Tahoma, Verdana, Arial, sans-serif; } </style> </head> <body> <h1>Welcome to nginx!</h1> <p>If you see this page, the nginx web server is successfully installed and working. Further configuration is required.</p>
<p>For online documentation and support please refer to <ahref="http://nginx.org/">nginx.org</a>.<br/> Commercial support is available at <ahref="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p> </body> </html>
当把pod 手动删除时,会重新创建,因为首次创建pod 时指定了 replicas=1
1
# kubectl delete pod nginx-deploy-55d8d67cf-qwlc2
1 2 3
# kubectl get pods -o wide NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES nginx-deploy-55d8d67cf-qj9z8 1/1 Running 0 5m44s 10.244.1.2 node01 <none> <none>
暴露服务端口
1 2 3 4 5 6
# kubectl expose deployment nginx-deploy --name=nginx --port=80 --target-port=80 --protocol=TCP service/nginx exposed # kubectl get svc NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 2d16h nginx ClusterIP 10.96.181.70 <none> 80/TCP 52s
# curl 10.96.181.70 <!DOCTYPE html> <html> <head> <title>Welcome to nginx!</title> <style> body { width: 35em; margin: 0 auto; font-family: Tahoma, Verdana, Arial, sans-serif; } </style> </head> <body> <h1>Welcome to nginx!</h1> <p>If you see this page, the nginx web server is successfully installed and working. Further configuration is required.</p>
<p>For online documentation and support please refer to <ahref="http://nginx.org/">nginx.org</a>.<br/> Commercial support is available at <ahref="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p> </body> </html> You have new mail in /var/spool/mail/root
查看 kube-system (kube-dns) 的CLUSTER-IP
1 2 3
# kubectl get svc -n kube-system NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE kube-dns ClusterIP 10.96.0.10 <none> 53/UDP,53/TCP,9153/TCP 2d16h
/ # wget -O - -q nginx <!DOCTYPE html> <html> <head> <title>Welcome to nginx!</title> <style> body { width: 35em; margin: 0 auto; font-family: Tahoma, Verdana, Arial, sans-serif; } </style> </head> <body> <h1>Welcome to nginx!</h1> <p>If you see this page, the nginx web server is successfully installed and working. Further configuration is required.</p>
<p>For online documentation and support please refer to <ahref="http://nginx.org/">nginx.org</a>.<br/> Commercial support is available at <ahref="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p> </body> </html>
1
# kubectl run myapp --image=ikubernetes/myapp:v1 --replicas=2
1 2 3 4
# kubectl get deployment -w NAME READY UP-TO-DATE AVAILABLE AGE myapp 1/2 2 1 70s nginx-deploy 1/1 1 1 60m
# kubectl get pods -l release NAME READY STATUS RESTARTS AGE nginx-deploy-55d8d67cf-v85hb 1/1 Running 0 8d pod-demo 2/2 Running 121 7d3h # kubectl get pods -l release=canary NAME READY STATUS RESTARTS AGE
标签选择器多条件选择
1 2 3
# kubectl get pods -l release=stable,app=myapp NAME READY STATUS RESTARTS AGE pod-demo 2/2 Running 121 7d3h
1 2 3 4 5 6
# kubectl get pods -l release!=stable NAME READY STATUS RESTARTS AGE client 1/1 Running 0 8d myapp-86984b4c7c-rf4lz 1/1 Running 0 27h myapp-86984b4c7c-wss2h 1/1 Running 0 28h nginx-deploy-55d8d67cf-v85hb 1/1 Running 0 8d
1 2 3 4 5 6 7 8 9
# kubectl get pods -l "release in (canary,beta,alpha)" NAME READY STATUS RESTARTS AGE nginx-deploy-55d8d67cf-v85hb 1/1 Running 0 8d # kubectl get pods -l "release notin (canary,beta,alpha)" NAME READY STATUS RESTARTS AGE client 1/1 Running 0 8d myapp-86984b4c7c-rf4lz 1/1 Running 0 27h myapp-86984b4c7c-wss2h 1/1 Running 0 28h pod-demo 2/2 Running 121 7d3h
1 2 3 4 5 6
# kubectl get nodes --show-labels NAME STATUS ROLES AGE VERSION LABELS node01 Ready <none> 10d v1.14.1 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=node01,kubernetes.io/os=linux node02 Ready <none> 10d v1.14.1 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=node02,kubernetes.io/os=linux node03 Ready <none> 10d v1.14.1 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=node03,kubernetes.io/os=linux master Ready master 10d v1.14.1 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=master,kubernetes.io/os=linux,node-role.kubernetes.io/master=
给node01 打额外标签,磁盘类型有固态硬盘
1 2 3 4
# kubectl label nodes node01 disktype=ssd # kubectl get nodes node01 --show-labels NAME STATUS ROLES AGE VERSION LABELS node01 Ready <none> 10d v1.14.1 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,disktype=ssd,kubernetes.io/arch=amd64,kubernetes.io/hostname=node01,kubernetes.io/os=linux