kubernets 快速入门
查看节点信息
kubectl get nodes
查看节点详细信息
kubectl describe node node1.leiyan.com
显示版本
kubectl version
显示集群信息
kubectl cluster-info
运行一个容器
kubectl run nginx-deploy --image=nginx:1.14-alpine --port=80 --replicas=1 kubectl run qzc-client --image=busyboy -it --replicas=1 --restart=Never
查看Pod 详细信息
[root@master ~]# kubectl get pods -o wide NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES nginx-deploy-5b66f76f68-cbgxt 1/1 Running 0 6m6s 10.244.2.14 node2.leiyan.com <none> <none> qinzc-7ffb658769-dvt6d 1/1 Running 0 4d4h 10.244.2.13 node2.leiyan.com <none> <none>
查看Deployment控制器信息
[root@master ~]# kubectl get deployment -o wide NAME READY UP-TO-DATE AVAILABLE AGE CONTAINERS IMAGES SELECTOR nginx-deploy 1/1 1 1 96s nginx-deploy nginx run=nginx-deploy qinzc 1/1 1 1 4d4h qinzc nginx run=qinzc
查看kubernet系统Pod信息
[root@master ~]# kubectl get pods -n kube-system -o wide NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES coredns-86c58d9df4-p2qkm 1/1 Running 1 13d 10.244.0.5 master.leiyan.com <none> <none> coredns-86c58d9df4-xfbqx 1/1 Running 1 13d 10.244.0.4 master.leiyan.com <none> <none> etcd-master.leiyan.com 1/1 Running 1 13d 192.168.1.90 master.leiyan.com <none> <none> kube-apiserver-master.leiyan.com 1/1 Running 1 13d 192.168.1.90 master.leiyan.com <none> <none> kube-controller-manager-master.leiyan.com 1/1 Running 2 13d 192.168.1.90 master.leiyan.com <none> <none> kube-flannel-ds-amd64-pnrwv 1/1 Running 3 13d 192.168.1.92 node2.leiyan.com <none> <none> kube-flannel-ds-amd64-s95zx 1/1 Running 2 13d 192.168.1.91 node1.leiyan.com <none> <none> kube-flannel-ds-amd64-x2nh8 1/1 Running 1 13d 192.168.1.90 master.leiyan.com <none> <none> kube-proxy-h2kjm 1/1 Running 1 13d 192.168.1.90 master.leiyan.com <none> <none> kube-proxy-mwq8z 1/1 Running 2 13d 192.168.1.91 node1.leiyan.com <none> <none> kube-proxy-ns596 1/1 Running 2 13d 192.168.1.92 node2.leiyan.com <none> <none> kube-scheduler-master.leiyan.com 1/1 Running 2 13d 192.168.1.90 master.leiyan.com <none> <none> [root@master ~]#
删除Pod
kubectl delete deployment nginx kubectl delete pod nginx-deploy-5b66f76f68-cbgxtddrrr
service服务暴露端口至集群
kubectl expose deployment nginx-deploy --name=nginx --port=80 --target-port=80 --protocol=TCP kubectl expose deployment myapp --port=80
Service暴露服务端口至集群外部
kubectl edit svc myapp 更改type类型为NodePort
查看service暴露端口详细信息
[root@master ~]# kubectl get svc -n kube-system -o wide NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR kube-dns ClusterIP 10.96.0.10 <none> 53/UDP,53/TCP 13d k8s-app=kube-dns
扩展Pod副本数量、扩容
kubectl scale --replicas=5 deployment myapp kubectl edit rs myapp 升级操作重建才会生效。
Pod默认为滚动更新/升级更新镜像
kubectl set image deployment myapp myapp=ikubernetes/myapp:v2
声明式更新
kubectl apply -f deploy-demo.yaml
显示更新、升级过程
kubectl rollout status deployment myapp
更新/升级回滚
kubectl rollout undo deployment myapp
修改、定义标签
kubectl lable TYPE NAME KEY_1=VAL_1 kubectl lable pods pod-demo release=canary kubectl lable pods pod-demo release=stable --overwrite kubectl lable pods pod-demo release=stable --overwrite kubectl lable node node1.leiyan.com disktype=ssd
标签过滤出Pod
标签选择器: 等值关系: =,==,!= 集合关系: KEY in (VALUE1,VALUE2,....) KEY notin (VALUE1,VALUE2,....) KEY !KEY (VALUE1,VALUE2,....) kubectl get pods -l app --show-lables kubectl get pods -l app,release #有app又有release标签的 kubectl get pods -l release=stable --show-lables kubectl get pods -l release!=stable --show-lables #没有release=stable标签的 kubectl get pods -L app,run kubectl get pods -l "release in (canary,beta,alpha)" #包含任一VALUE kubectl get pods -l "release notin (canary,beta,alpha)" #不包含任一VALUE
停留在世界边缘,与之惜别