k8s 常用命令记录

k8s 常用命令记录

获取failed状态的所有pod并删除

kubectl get pods --field-selector=status.phase=Failed -n ns-xx-xx | cut -d' ' -f 1 |xargs kubectl delete pod -n ns-xx-xx

监听endpoint

watch kubectl describe endpoints [endpoint name]

获取重启pod上一个pod的输出日志

kubectl logs pod-dev-79c5d99d9f-hxr5f -n pod-dev -c pod-dev --previous > a.log

获取集群信息

kubectl cluster-info

删除configmap

kubectl delete configmap fortune-config

查看容器环境变量

kubectl exec kubia-3inly env

在运行的容器中执行远程命令  –代表命令的结束,后面都是要在容器中执行的命令

kubectl exec kubia-7nogl -- curl -s http: //10.111.249 .153

查看pod描述

kubectl explain pods

查看hpa

kubectl get hpa --all-namespaces

删除hpa

kubectl delete hpa go-service-auto-scale -n ms-service

查看所有的pod

kubectl get po --all-namespaces -o wide

查看pod的标签

kubectl get pods --show-labels

测试资源

kubectl create -f ./hello-world.yaml --validate

删掉pod

kubectl delete pods redis

查看所有的namespace

kubectl get namespaces

执行yaml

kubectl create -f ./namespaces.yaml

创建namespace

kubectl create namespace new-namespace

删除namespace

kubectl delete namespaces new-namespace

删除deployment

kubectl delete deployment sonarqube

扩容deployment

kubectl scale deployment nginx-deployment --replicas 10

查看deployment

kubectl get deployments

查看replica(RS)

kubectl get rs

查看deployment描述

kubectl describe deployments

查看deployment revision记录

kubectl rollout history deployment/nginx-deployment

查看cronjob

kubectl get cronjob

查看job执行状态

kubectl get jobs

查看pod日志

kubectl logs hello-1542189960-9nqf5

查看所有svc

kubectl get svc -o wide

查看svc和对应selector的描述

kubectl describe svc nginxsvc

查看endpoint

kubectl get ep

查看节点的环境变量

kubectl exec my-nginx-6isf4 -- printenv

节点缩容/扩容

kubectl scale rc my-nginx --replicas=0; 
kubectl scale rc my-nginx --replicas=2;

获取secrets

kubectl get secrets

删除DaemonSet

kubectl delete DaemonSet fluentd

删除yaml的配置

kubectl delete -f consol-agent.yaml

进入pod

kubectl exec -it xe-agent-5685546b46-7bf57 -n consol-dev bash

查看并指定namespace

kubectl describe deployment xe-agent -n consol-dev

发表评论