bash
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
kubectl version										# 查看集群版本
kubectl api-versions								# 查看API版本
kubectl get cs										# 查看集群健康
kubectl cluster-info								# 查看集群信息
kubectl cluster-info dump --output-directory=<dir>	# 输出集群状态
kubectl get namespace                               # 查看名称空间

kubectl cordon <node>								# 设置node为不可调度

kubectl annotate pods <pod> <name>=<'我是注解'>		# 添加KV形式对注解
kubectl get pod <pod> -o json						# 查看Pod信息	

kubectl apply -f nginx-deploy.yaml                 # 修改yaml立刻生效
kubectl create -f nginx-deploy.yaml                # 创建服务

kubectl delete node <name>							# 移除node
kubectl delete pods <name> --force  				# 强制pod
kubectl delete pods,services -l name=<label> --include-uninitialized      # 删除pod和service
kubectl delete -f ./pod.json						# 删除 pod.json 文件中定义的类型和名称的 pod
kubectl drain k8s-node								# 清空node

kubectl describe deployment/<name> -n <namespace>	# 查看deployment信息
kubectl describe pods <podname> -n <namespace>		# 查看pod容器信息
kubectl describe service/<app> -n <namespace>		# 查看服务的信息


kubectl edit deployment/chinapopin-vsitregist-web -n chinapopin-system-test # 编辑deployment
kubectl edit pod/visitregister-7qvvz  -n chinapopin-system-test             # 编辑pod
kubectl edit svc/visitregister-manager-test -n chinapopin-system-test       # 编辑名为visitregister-manager-test 的 service

kubectl exec -it vis-7qvvz /bin/sh -n namspace-test    # 进入到pod容器
kubectl exec nginx-pod -- ls /                         # 在已存在的容器中执行命令(只有一个容器的情况下)
kubectl exec nginx-pod -c my-container -- ls /         # 在已存在的容器中执行命令(pod 中有多个容器的情况下)

kubectl explain pods,svc                           # 获取 pod 和 svc 的文档
kubectl expose rc nginx --port=80 --target-port=8000 #更新单容器 pod 的镜像版本(tag)到 v4

kubectl get deploy -o wide --all-namespaces        #查看所有deployment信息
kubectl get events                  # 查看事件
kubectl get nodes -o wide                          #查看节点信息
kubectl get pod nginx-pod -o yaml | sed 's/\(image: myimage\):.*$/\1:v4/' | kubectl replace -f -
kubectl get pods -o wide --all-namespaces          #查看所有pod信息
kubectl get rc -o wide --all-namespaces                                                     #查看所有ReplicationController
kubectl get service -o wide --all-namespaces       #查看所有服务信息
kubectl label pods nginx-pod new-label=awesome                # 添加标签
kubectl logs -f nginx-pod                              # 流式输出 pod 的日志(stdout)
kubectl logs -f nginx-pod -c my-container              # 流式输出 pod 中容器的日志(stdout,pod 中有多个容器的情况下使用)
kubectl logs nginx-pod                                 # dump 输出 pod 的日志(stdout)
kubectl logs nginx-pod -c my-container                 # dump 输出 pod 中容器的日志(stdout,pod 中有多个容器的情况下使用)
kubectl port-forward nginx-pod 5000:6000               # 转发 pod 中的 6000 端口到本地的 5000 端口
kubectl rolling-update python --image=image:v2              # 更新 frontend pod 中的镜像
kubectl rolling-update python-v1 -f python-v2.json          # 滚动更新 pod frontend-v1
kubectl rolling-update python-v1 python-v2 --image=image:v2 # 更新资源名称并更新镜像
kubectl rolling-update python-v1 python-v2 --rollback       # 退出已存在的进行中的滚动更新
kubectl rollout restart deployment busybox-deployment-v1    # 重启deploy的所有部署pod为nginx RC 创建服务,启用本地 80 端口连接到容器上的 8000 端口
kubectl rollout status deploy deployment/mysql                    # 查看变更进度

kubectl run -i --tty busybox --image=busybox       # 创建带有终端的pod
kubectl run -i --tty busybox --image=busybox -- sh  # 交互式 shell 的方式运行 pod
kubectl run mybusybox --image=busybox --replicas=5 # 启动多个pod
kubectl attach <pod> -c <container> -ti				# 连接到Pod(attach: 附加,连接)

# scale: 规模,比例,攀登
kubectl scale --current-replicas=2 --replicas=3 deployment/mysql		# 2个变成3个
kubectl scale --replicas=3 -f foo.yaml									# 缩放“foo”中指定的资源。
kubectl scale --replicas=3 rc/foo rc/bar								# 变更多个控制器的数量
kubectl autoscale deployment foo --min=2 --max=10						# 自动扩展 deployment 'foo'

kubectl top node <node> 						# 显示node指标度量
kubectl top pod <pod> --containers				# 显示pod指标度量
kubectl uncordon <node> 						# 解禁node可调度

「真诚赞赏,手留余香」

Hollson码夫庄园

嗯,我的梦想是被读者的稿费包养~

使用微信扫描二维码完成支付

Hollson

评论