K8S常用命令

What is Kubernetes?

什么是 K8s?

Kubernetes is a platform for managing containerized workloads. Kubernetes orchestrates computing, networking and storage to provide a seamless portability across infrastructure providers

Kubernetes是一个用于管理容器化工作负载的平台。 Kubernetes协调计算,网络和存储以提供跨基础架构提供商的无缝移植

集群信息

> kubectl config
> kubectl cluster -info
> kubectl get componentstatuses

查看资源信息

节点信息

> kubectl get no
> kubectl get no -o wide
> kubectl describe no
> kubectl get no -o yaml
> kubectl get node --selector=[label_name]
> kubectl get nodes -o jsonpath='{.items[*].status.addresses[?(@.type=="ExternalIP")].address}'
> kubectl top node [ node_name]

Pods

> kubectl get po
> kubectl get po -o wide
> kubectl describe po
> kubectl get po --show -labels
> kubectl get po -l app=nginx
> kubectl get po -o yaml
> kubectl get pod [pod_name] -o yaml --export
> kubectl get pod [pod_name] -o yaml --export > nameoffile.yaml
> kubectl get pods --field-selector status.phase=Running

命名空间

> kubectl get ns
> kubectl get ns -o yaml
> kubectl describe ns

服务

> kubectl get svc
> kubectl describe svc
> kubectl get svc -o wide
> kubectl get svc -o yaml
> kubectl get svc --show-labels

 

部署

> kubectl get deploy
> kubectl describe deploy
> kubectl get deploy -o wide
> kubectl get deploy -o yaml

配置地图

> kubectl get cm
> kubectl get cm -n=[namespace]
> kubectl get cm -n=[namespace] -o yaml 
> kubectl get cm --all -namespaces
> kubectl get cm --all -namespaces -o yaml

 

日志集

> kubectl logs [pod_name]
> kubectl logs [pod_name] -n=[namespace]
> kubectl logs --since=1h [pod_name]
> kubectl logs --tail=20 [pod_name]
> kubectl logs -f -c [container_name][pod_name]
> kubectl logs [pod_name] > pod.log

 

安全集

> kubectl get secrets
> kubeclt get secrets -n=[namespace]
> kubectl get secrets -n=[namespace] -o yaml 
> kubectl get secrets --all -namespaces
> kubectl get secrets -o yaml

 

副本集

> kubectl get rs
> kubectl describe rs
> kubectl get rs -o wide
> kubectl get rs -o yaml

 

posted @ 2020-04-25 22:05  漠漠颜  阅读(407)  评论(0编辑  收藏  举报