k8s常用命令

在这里插入代码片k8s版本 1.6.2

一、常用命令

1. node

查看node

kubectl get node 或 kubectl get nodes

[root@docker176 ~]# kubectl get node
NAME             STATUS    AGE       VERSION
192.168.14.175   Ready     7d        v1.6.2
192.168.14.176   Ready     33m       v1.6.2

删除node

kubectl delete node nodeName

2. 查看namespaces

kubectl get ns 等同于
kubectl get namespaces

[root@docker176 ~]# kubectl get ns
NAME          STATUS    AGE
b1            Active    78d
b1-z1         Active    50d
b111          Active    50d
default       Active    79d
demo          Active    13d
kube-public   Active    79d
kube-system   Active    79d
monitoring    Active    8d

不带 -n 或 --namespaces

3. 查看指定空间信息

kubectl get all 等同于 kubectl get pod,svc,deploy,rs。all 包括 所有 pod,svc,deploy,rs
kubectl get all 查看namespace=default的空间,查看指定空间 kubectl -n monitoring get all

[root@docker176 ~]# kubectl get all
NAME                           READY     STATUS    RESTARTS   AGE
po/es-kibana-744328589-s6ps6   3/3       Running   6          7d
po/logstash-agent-jqpm3        1/1       Running   2          7d
po/logstash-agent-pm0dl        1/1       Running   0          42m

NAME             CLUSTER-IP     EXTERNAL-IP   PORT(S)                         AGE
svc/es-kibana    10.254.0.137   <nodes>       6379:31379/TCP,5601:31601/TCP   48d
svc/fcsp-es      10.254.0.136   <nodes>       9200:31200/TCP                  48d
svc/kubernetes   10.254.0.1     <none>        443/TCP                         79d

NAME               DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
deploy/es-kibana   1         1         1            1           48d

NAME                     DESIRED   CURRENT   READY     AGE
rs/es-kibana-744328589   1         1         1         48d

4.查看describe信息

kubectl -n namespace describe pod podName

kubectl -n ${namespace} describe pod ${podName}

二、常用get命令说明

[root@docker176 ~]# kubectl get --help
Display one or many resources. 

Valid resource types include: 

  * all  
  * certificatesigningrequests (aka 'csr')  
  * clusters (valid only for federation apiservers)  
  * clusterrolebindings  
  * clusterroles  
  * componentstatuses (aka 'cs')  
  * configmaps (aka 'cm')  
  * daemonsets (aka 'ds')  
  * deployments (aka 'deploy')  
  * endpoints (aka 'ep')  
  * events (aka 'ev')  
  * horizontalpodautoscalers (aka 'hpa')  
  * ingresses (aka 'ing')  
  * jobs  
  * limitranges (aka 'limits')  
  * namespaces (aka 'ns')  
  * networkpolicies  
  * nodes (aka 'no')  
  * persistentvolumeclaims (aka 'pvc')  
  * persistentvolumes (aka 'pv')  
  * pods (aka 'po')  
  * poddisruptionbudgets (aka 'pdb')  
  * podsecuritypolicies (aka 'psp')  
  * podtemplates  
  * replicasets (aka 'rs')  
  * replicationcontrollers (aka 'rc')  
  * resourcequotas (aka 'quota')  
  * rolebindings  
  * roles  
  * secrets  
  * serviceaccounts (aka 'sa')  
  * services (aka 'svc')  
  * statefulsets  
  * storageclasses  
  * thirdpartyresources  

This command will hide resources that have completed, such as pods that are in the Succeeded or Failed phases. You can
see the full results for any resource by providing the '--show-all' flag. 

By specifying the output as 'template' and providing a Go template as the value of the --template flag, you can filter
the attributes of the fetched resources.

Examples:
  # List all pods in ps output format.
  kubectl get pods
  
  # List all pods in ps output format with more information (such as node name).
  kubectl get pods -o wide
  
  # List a single replication controller with specified NAME in ps output format.
  kubectl get replicationcontroller web
  
  # List a single pod in JSON output format.
  kubectl get -o json pod web-pod-13je7
  
  # List a pod identified by type and name specified in "pod.yaml" in JSON output format.
  kubectl get -f pod.yaml -o json
  
  # Return only the phase value of the specified pod.
  kubectl get -o template pod/web-pod-13je7 --template={{.status.phase}}
  
  # List all replication controllers and services together in ps output format.
  kubectl get rc,services
  
  # List one or more resources by their type and names.
  kubectl get rc/web service/frontend pods/web-pod-13je7
  
  # List all resources with different types.
  kubectl get all
  • 0
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值