k8s基础概念和常用操作
1、基本概念搞清楚master, node, pod,controller(deployoment,ReplicaSet,DaemonSet,StatefulSet,Job),service概念,在此基础上先学会通过kubernetes命令行客户端 kubectl管理应用。(1)get#login master node,list nodes in cluster$ kubect...
基本概念
搞清楚master, node, pod,controller(deployoment,ReplicaSet,DaemonSet,StatefulSet,Job), service概念,在此基础上先学会通过kubernetes命令行客户端 kubectl管理应用。
1、常用操作
node/pod
$ kubectl -n prod get pod
NAME READY STATUS RESTARTS AGE
app1-c6766495b-6497w 1/1 Running 0 2d1h
app2-6c4d8cfcf6-44pbc 1/1 Running 0 15d
bash-4.2$ kubectl -n prod -o wide get pod #以wide形式查看
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE
app1-c6766495b-6497w 1/1 Running 0 47h 10.10.10.10 k8s-node12 <none>
app2-6c4d8cfcf6-44pbc 1/1 Running 0 14d 11.11.11.11 k8s-node2 <none>
$kubectl exec -it podname -n namespace bash #以bash方式进入到pod
$ kubectl get node
NAME STATUS ROLES AGE VERSION
k8s-build0 Ready <none> 30d v1.12.6
k8s-build1 Ready <none> 30d v1.12.6
$ kubectl get node -n prod -o wide | head -2
NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME
xx-prod-k8s-xx-node0 Ready <none> 440d v1.12.6 10.217.12.2 <none> CentOS Linux 7 (Core) 4.4.175-1.xx.xx.x86_64 docker://xx
2、controller
deployoment,ReplicaSet,DaemonSet,StatefulSet,Job
$ kubectl get cs
NAME STATUS MESSAGE ERROR
scheduler Healthy ok
controller-manager Healthy ok
etcd-1 Healthy {"health":"true"}
etcd-2 Healthy {"health":"true"}
etcd-0 Healthy {"health":"true"}
deployment
$ kubectl get deploy -n prod -l app=xx-xx #查看应用xx-xx的deployment
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
xx-prod-xx-xx 1 1 1 1 402d
$ kubectl get deploy -n prod -l app=fx-accessor -o wide #以wide形式查看
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE CONTAINERS IMAGES SELECTOR
xx-prod-xx-xx 1 1 1 1 402d xx-xx harbor-xx.s.xx.com/xx/xx-xx:prod-xx-869302b2-6 BlueGreenVersion=blue,app=fx-accessor,namespace=prod,region=bd,track=stable,zone=prod
$ kubectl get deploy -n prod -l app=xx-xx -o yaml #以yaml形式查看
$ kubectl edit deploy xx-prod-xx-xx -n prod #修改deploy
Edit cancelled, no changes made.
ReplicaSet
#下面展示了线上存在多个版本,其中rs xx-prod-xx-xx-7dd847bbb8 为异常版本,需要下掉对应的pod
$ kubectl get rs -n prod -l app=xx-xx
NAME DESIRED CURRENT READY AGE
xx-prod-xx-xx-55b997c5fc 0 0 0 308d
xx-prod-xx-xx-577f556547 0 0 0 237d
xx-prod-xx-xx-5cc7bfb97d 0 0 0 293d
xx-prod-xx-xx-6bd7b7c85f 0 0 0 231d
xx-prod-xx-xx-7675b6fdf8 1 1 1 21d
xx-prod-xx-xx-7dd847bbb8 1 1 1 98d
xx-prod-xx-xx-8474fd488 0 0 0 273d
#下面通过scacle 将对应的rs下的replicas数调为0
$ kubectl scale rs xx-prod-xx-xx-7dd847bbb8 --replicas=0 -n prod
replicaset.extensions/xx-prod-xx-xx-7dd847bbb8 scaled
$ kubectl get rs -n prod -l app=xx-xx #查看效果
NAME DESIRED CURRENT READY AGE
xx-prod-xx-xx-55b997c5fc 0 0 0 308d
xx-prod-xx-xx-577f556547 0 0 0 237d
xx-prod-xx-xx-5cc7bfb97d 0 0 0 293d
xx-prod-xx-xx-6bd7b7c85f 0 0 0 231d
xx-prod-xx-xx-7675b6fdf8 1 1 1 21d
xx-prod-xx-xx-7dd847bbb8 0 0 0 98d
xx-prod-xx-xx-8474fd488 0 0 0 273d
3、service
4、k8s-proxy
更多推荐
所有评论(0)