# 查看test空间的service
kubectl get svc -n test
# 查看test空间中cms的yaml文件
kubectl get svc cms -o=yaml -n test
# 查看集群节点
kubectl get nodes
# 查看有哪些空间名
kubectl get namespace
# 查看test空间的项目状态
kubectl get pods -n test
# -o wide显示所有具体信息
kubectl get pods -n test -o wide
# 查看test命名空间中名称为cms的pod的日志
kubectl logs -f cms -n test
# 查看test命名空间中cms的k8s执行动作
kubectl describe pods cms -n test
# 删除容器
kubectl delete -f nginx.yaml
# 创建容器
kubectl create -f nginx.yaml
# 查看test命名空间中所有应用映射的dns(负载)地址
kubectl get svc -n test -o wide
# 查看test命名空间中所有pod的具体信息
kubectl get pods -n test -o wide
# 查看test命名空间中cms应用映射的dns(负载)地址详细信息
kubectl describe svc cms -n test
# 查看namespace为common的yaml文件
kubectl get ns common -o yaml
# 查看test 命名空间下fastdfs-0的yaml文件
kubectl get pod -n testfastdfs-0 -o yaml
# 查看test命名空间下<podname>的描述信息
kubectl describe pod <podname> -n test
# 编辑运行的资源对象nginx
kubectl edit deploy nginx
# 复制pod:mymss-** 的/etc/hosts的文件到本地/tmp目录
kubectl cp mymss-**:/etc/hosts /tmp
# 回滚nginx到当前版本的上一个版本
kubectl rollout undo deployment nginx
# 回滚nginx到指定的revision=2版本
kubectl rollout undo deployment nginx --to-revision=2
# 重启pod
方法1:
kubectl get pod {podname} -n {namespace} -o yaml | kubectl replace --force -f -
方法2:
kubectl rollout restart deployment xxxx
说明:会先删除旧的pod再启动新pod
# 查看test命名空间下的项目
kubectl get deployment -n test
# 修改tes命名t空间下项目jenkins的pods节点数从1改为0
kubectl scale --current-replicas=1 --replicas=0 deployment/jenkins -n test
# 把pod的节点改为1
kubectl scale deployment.apps/mymss-deployment --replicas=1 -n test
通过k8s服务器登录容器
nginx-554c8d959-5gzgm 实例(POD)
test 命名空间
kubectl exec -it nginx-554c8d959-5gzgm /bin/bash -n test