k8s命令大全

古之立大事者,不惟有超世之才,亦必有坚忍不拔之志。这篇文章主要讲述k8s命令大全相关的知识,希望能为你提供帮助。
查看当前k8s集群下的所有pod,-A参数:

# kubectl get pod -A

 
查看default 名称空间下的pod:
# kubectl get pod


去掉-A参数,默认查看就是default下。
 
创建一个pod,pod中运行2个容器redis和nginx:
[root@master ~]# cat pod.yaml
apiVersion: v1
kind: Pod#一定要大写
metadata:
name: myapp
labels:
app: myapp
version: v1
spec:
containers:
- name: app
image: redis
- name: test
image: nginx

kubectl describe查看pod的运行状况信息:
# kubectl describe pod myapp

可以查看到两个app和test容器信息:
 
查看pod下两个容器中一个容器的log信息-c参数:
# kubectl logs myapp -c test

 
登录pod下其中一个容器:
kubectl exec myapp -c test -it -- bash

 
实时查看pod的状态,-w参数类似linux下的watch命令:
# kubectl get pod -w

 
查看pod的详细信息(IP,部署node)
# kubectl get pod myapp -o wide

 
查看pod标签:--show-labels

# kubectl get pod -n nginx-example --show-labels

 
修改pod标签:
# kubectl label --overwrite pods nginx-deployment-7cd5ddccc7-5knxt app=nginx2 -n nginx-example
pod/nginx-deployment-7cd5ddccc7-5knxt labeled

 
Pod扩容:
# kubectl scale deployment nginx-deployment --replicas=5

 
查看RS:
# kubectl get rs

 
更新deployment 镜像:更新deployment下的nginx-deployment镜像

# kubectl set image deployment/nginx-deployment nginx=nginx1.8

 
回滚deployment镜像:回滚deployment下的nginx-deployment

# kubectl rollout undo deployment/nginx-deployment

 
查看deployment回滚状态:
# kubectl rollout status deploy/nginx-deployment

 
查看deployment回滚的历史记录:
# kubectl rollout history deploy/nginx-deployment

 
Service新增一个  external ip:
[root@master helm-chart]#kubectl patch svc app-nginx-nginx-ingress-p {"spec": {"type": "LoadBalancer", "externalIPs":["192.168.1.15"]}}

【k8s命令大全】 
查看ingress绑定:
# kubectl get ing -A

 
登录pod下的容器:
kubectl exec myapp -c test -it -- bash

创建configmap:--from-file=文件/目录都行。

[root@master ~]# kubectl create configmap mew --from-file=configmap.yaml
configmap/mew created
[root@master ~]# cat configmap.yaml
name=mew
age=20

 
?查看configmap:
# kubectl get cm

 
查看configmap的yaml配置:
# kubectl get cm my-release-nginx-ingress-o yaml

 
键值对方式创建configmap:
[root@master ~]# kubectl create configmap mew-info --from-literal=address=henan
configmap/mew-info created

 
查看configmap的详细信息:
[root@master ~]# kubectl describe cm mew-info

 
Service增加externalIPs IP:
[root@master ~]# kubectl patch svc my-release-nginx-ingress -p {"spec": {"type": "LoadBalancer", "externalIPs":["192.168.1.15"]}} -n istio-system
service/my-release-nginx-ingress patched

 

    推荐阅读