Kubernetes Common Commands

Source: Internet
Author: User

#1. Query information kubectl get [services to be queried]

Node nodes
Componentstatuses abbreviated CS Component Status
Namespaces abbreviated NS name space
Pod pod info Add (-o wide) view run node
Service Query Service
deployments --all-namespaces   Kind Classification Query
all --all-namespaces 
--all-namespaces  所有命名空间

###将信息输入为yaml格式

Kubectl get pod [pod name]-O YAML

NGINX-6F858D4D45-SGWDF 1/1 Running 0 3h
[[email protected] ~]# kubectl get pod nginx-6f858d4d45-sgwdf-o yaml
Apiversion:v1
Kind:pod
Metadata
creationtimestamp:2018-09-01t10:01:55z
generatename:nginx-6f858d4d45-

... Omitted





#2.删除
1.删除节点
kubectl delete node node1

2. Delete Pod
delete pod $(pod_name) -n $(namespace-name)

3. Delete Services
delete svc $(svc_name) -n $(namespace-name)

#3.创建
1.创建pod
kubectl create -f  create_pod.yaml 
2.更新pod
kubectl rolling-update pod_v1 -f pod_v2.yaml
3.回滚
kubectl rolling-update pod_v2 --rollback


Problem Locator

1. Querying Object Details

kubectl describe pod [pod名] -n  [所在命名空间]

[[email protected] ~]# kubectl describe pod client-n default
Name:client
Namespace:default
priority:0
Priorityclassname: <none>
node:node1/10.0.0.40
Start Time:sat, Sep 2018 20:12:08 +0800
Labels:run=client
Annotations: <none>
Status:failed
ip:10.244.1.5

..........

2. Query log

kubectl logs -f [pod名] -n  [所在命名空间]

[Email protected] ~]# kubectl logs-f client-n Default
/ #
/# ls
bin etc proc Sys usr
Dev Home Root tmp var
/# cat/etc/resolv.conf
NameServer 10.96.0.10
Search Default.svc.cluster.local svc.cluster.local cluster.local
Options Ndots:5
/# IP A
1:lo: <LOOPBACK,UP,LOWER_UP> MTU 65536 qdisc noqueue Qlen 1000
Link/loopback 00:00:00:00:00:00 BRD 00:00:00:00:00:00
inet 127.0.0.1/8 Scope host Lo
Valid_lft Forever Preferred_lft Forever
3: [Email protected]: <BROADCAST,MULTICAST,UP,LOWER_UP,M-DOWN> MTU 1450 Qdisc Noqueue
Link/ether 0a:58:0a:f4:01:05 BRD FF:FF:FF:FF:FF:FF
inet 10.244.1.5/24 Scope Global eth0
Valid_lft Forever Preferred_lft Forever

......... Omitted

3. Enter container Run command, if Pod has more than one container, use-C to specify container

KUBECTL exec [pod name]-C [Docker image] [command executed]-n [namespace]

[[email protected] ~]# kubectl exec nginx-6f858d4d45-sgwdf-c nginx hostname-n default
Nginx-6f858d4d45-sgwdf

 
 
 
 


Kubernetes Common Commands

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.