k8s
show 查看
# 查看指定ns内 pod 和 svc
kubectl -n cwx get pod,svc -o wide
# 查看 pod 描述信息
kubectl describe pod pod_name -n kube-system
# 最新日志
kubectl -n dev logs app-6dcf664d86-jrnb2 --tail 500 -f
# 输出前一次停机前的日志
kubectl logs <pod-name> --previous
# 综合查看
kubectl get pods --all-namespaces
kubectl get pods --show-labels
kubectl get pods --show-labels --selector app=mysql容器管理
# 拷贝文件出来
kubectl -n uat-1 cp pod_name:/me/xxxx.xlsx xxxx.xlsx
# 在某个容器内执行命令 - 测试 dns 解析
kubectl exec -n cwx pods/redis-sfs-0 -- nslookup mygoweb
kubectl exec -it <pod name> -- bash # 交互式执行
# 查找 Pod 所在节点
kubectl -n cwx describe pod gatus-68cbd45f6c-p6tm6 | grep Node:发布管理
kubectl -n uat scale deployment me-x-x --replicas=0 # 调整副本数量
# kustomize
kubectl kustomize overlays/dev # show 配置 - 不应用
kubectl apply -k overlays/dev # 部署 - 应用集群管理
kubectl get events -A # 查看集群事件
kubectl cluster-info # 集群连接信息
kubectl cluster-info dump > dump.log # 集群详细信息
# 证书
kubectl get csr # 查看最近的证书请求
kubectl certificate approve node-csr-xxxxxxxx # 批准证书请求
kubectl delete events --all --all-namespaces # 删除全部事件
kubectl delete events --all -n <namespace>
# 查看 ns 中全部的资源对象
kubectl get all -n cwx
kubectl api-resources --verbs=list --namespaced -o name | xargs -n 1 kubectl get --show-kind --ignore-not-found -n cwx节点管理
# 驱逐pod
kubectl drain node-161 --ignore-daemonsets=true --delete-emptydir-data=true
# 恢复节点可用标签
kubectl uncordon node-161客户端管理
kubectl config set-context --current --namespace=cwx
kubectl port-forward service/<service name> <localPort>:<servicePort>
kubectl port-forward <podName> <localPort>:<podPort> --namespace kube-system
# 测试 dns 解析
kubectl run dns-test --image=busybox:1.28 --rm -it --restart=Never -- nslookup kubernetes.default最后更新于