You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
> Kubernetes is a platform for managing containerized workloads. Kubernetes orchestrates computing, networking and storage to provide a seamless portability across infrastructure providers
6
6
7
7
## Cluster Info
8
-
```yaml
9
-
> kubectl config
10
-
> kubectl cluster -info
11
-
> kubectl get componentstatuses
8
+
```sh
9
+
> kubectl config # get the available commands that config has
10
+
> kubectl config current-context # get the current context of the cluster
11
+
> kubectl config get-clusters # get the k8s cluster
12
+
> kubectl config get-contexts # get the contexts that cluster acquired
13
+
> kubectl config rename-context # to rename the context of the cluster
14
+
> kubectl config set-context --current --namespace=[your namespace] # change the current context of the cluster
15
+
> kubectl config view # view the config of the cluster
16
+
> kubectl cluster-info # get the info about the cluster dns and master node
17
+
> kubectl get componentstatuses # get the status of the components in the cluster like scheduler
12
18
```
13
19
14
20
## Viewing Resource Information
15
21
16
22
#### Nodes
17
23
```bash
18
-
> kubectl get no
19
-
> kubectl get no -o wide
20
-
> kubectl describe no
21
-
> kubectl get no -o yaml
22
-
> kubectl get node --selector=[label_name]
23
-
> kubectl get nodes -o jsonpath='{.items[*].status.addresses[?(@.type=="ExternalIP")].address}'
24
-
> kubectl top node [ node_name]
24
+
> kubectl get no # get the nodes you have
25
+
> kubectl get no -o wide # get the wide description of the nodes
26
+
> kubectl get no --all-namespaces # get the all available nodes in the cluster
27
+
> kubectl get no --show-labels=[bool(true/false)] # get the cluster info with the labels
28
+
> kubectl get no -o json # get the node output in json
29
+
> kubectl get no --watch=true # get the status of the nodes by every 2 seconds
30
+
> kubectl get no --sort-by='{.metadata.name}'# get the sorted info of the nodes
31
+
> kubectl get --filename=[path to the directory or yaml file] # get the status of nodes using file path
32
+
> kubectl get no -o yaml # get the nodes in yaml format
33
+
> kubectl get no --selector=[label_name] # get the nodes with the label name
34
+
> kubectl get no -o jsonpath='{.items[*].status.addresses[?(@.type=="ExternalIP")].address}'# get the node in the given path of json file
35
+
> kubectl describe no # Describe the nodes
36
+
> kubectl describe no --all-namespaces # Describe the nodes in all namespaces
37
+
> kubectl describe no [node_name] # Describe a particular node
38
+
> kubectl describe --filename=[path to the directory or yaml file] # get the described nodes using file path
39
+
> kubectl delete no [node_name] # to delete the node with give node name
25
40
```
26
41
#### Pods
27
42
```bash
28
-
> kubectl get po
29
-
> kubectl get po -o wide
30
-
> kubectl describe po
31
-
> kubectl get po --show -labels
32
-
> kubectl get po -l app=nginx
33
-
> kubectl get po -o yaml
34
-
> kubectl get pod [pod_name] -o yaml --export
35
-
> kubectl get pod [pod_name] -o yaml --export > nameoffile.yaml
36
-
> kubectl get pods --field-selector status.phase=Running
43
+
> kubectl get po # get the pods in the current namespace
44
+
> kubectl get po -o wide # get the pods in the current namespace in wide
45
+
> kubectl get po --show-labels # get the pods with their labels
46
+
> kubectl get po -l app=nginx # get the pods with the label name app=nginx
47
+
> kubectl get po -o yaml # get the pods output in yaml format
48
+
> kubectl get pod [pod_name] -o yaml --export # get the output in yaml format of a particular pod
49
+
> kubectl get pod [pod_name] -o yaml --export > nameoffile.yaml # export the output of pod in some file
50
+
> kubectl get pods --field-selector status.phase=Running # check that pods which are running
51
+
> kubectl get po --all-namespaces # get pods of all the namespaces
52
+
> kubectl get po --allow-missing-template-keys=true # If true, ignore any errors in templates when a field or map key is missing in the template. Only applies to golang and jsonpath output formats.
53
+
> kubectl get po --chunk-size=500 # Return large lists in chunks rather than all at once. Pass 0 to disable.
54
+
> kubectl get po -o json # get the pods in json format
55
+
> kubectl get po --watch=true # apply watch to get the status of every pod in 2 seconds
56
+
> kubectl get po --sort-by='{.metadata.name}'# get the sorted info about the pods
57
+
> kubectl describe po # describe the pods
58
+
> kubectl describe po --all-namespaces # describe the pods in all namespaces
59
+
> kubectl describe po [pod_name] # describe the pod given with the name
60
+
> kubectl delete po [pod_name] # delete the given name pod
61
+
> kubectl delete pods --all # delete all the pods in current namespace
37
62
```
38
63
39
64
#### Namespaces
40
65
```bash
41
-
> kubectl get ns
42
-
> kubectl get ns -o yaml
43
-
> kubectl describe ns
66
+
> kubectl get ns # get all the namespaces
67
+
> kubectl get ns -o yaml # get the output of namespace in yaml format
68
+
> kubectl get ns -o json # get the output of namespace in json format
69
+
> kubectl describe ns [your namespace] # describe the given namespace
70
+
> kubectl describe ns # describe all the namespaces
71
+
> kubectl delete ns [your namespace] # delete the given namespace
44
72
```
45
73
46
74
#### Services
47
75
```bash
48
-
> kubectl get svc
49
-
> kubectl describe svc
50
-
> kubectl get svc -o wide
51
-
> kubectl get svc -o yaml
52
-
> kubectl get svc --show-labels
76
+
> kubectl get svc # get the services in current namespace
77
+
> kubectl get svc -o wide # get the services in wide format
78
+
> kubectl get svc -o yaml # get the services in yaml format
79
+
> kubectl get svc --show-labels # get the services with their labels
80
+
> kubectl get svc --all-namespaces # get services in all namespaces
81
+
> kubectl describe svc # describe all the services
82
+
> kubectl describe svc [service_name] # describe the given service name
83
+
> kubectl describe svc --all-namespaces # describe the services in all namespaces
84
+
> kubectl delete svc -l key=value # delete the svc with the given label
85
+
> kubectl delete svc --all # delete all the svc in current namespace
53
86
```
54
87
55
88
#### Deployments
56
89
```bash
57
-
> kubectl get deploy
58
-
> kubectl describe deploy
59
-
> kubectl get deploy -o wide
60
-
> kubectl get deploy -o yaml
90
+
> kubectl get deploy # get the deployments in current namespace
91
+
> kubectl get deploy -o wide # get the deployments in wide info
92
+
> kubectl get deploy -o yaml # get the deployments in yaml format
93
+
> kubectl get deploy --all-namespaces # get the deployments in all namespaces
94
+
> kubectl describe deploy # describe all the deployments
95
+
> kubectl describe deploy [deploy_name] # describe the given name deployment
96
+
> kubectl describe deploy --all-namespaces # describe the deployments in all namespaces
97
+
> kubectl delete deploy [deploy_name] # delete the given name deployment
98
+
> kubectl delete deploy --all # delete all the deployments in current namespace
61
99
```
62
100
63
101
#### ConfigMaps
64
102
```bash
65
-
> kubectl get cm
66
-
> kubectl get cm -n=[namespace]
67
-
> kubectl get cm -n=[namespace] -o yaml
68
-
> kubectl get cm --all -namespaces
69
-
> kubectl get cm --all -namespaces -o yaml
103
+
> kubectl get cm # get the current config map
104
+
> kubectl get cm -n=[namespace] # get the config map given namespace
105
+
> kubectl get cm -n=[namespace] -o yaml # get the config map given namespace in yaml format
106
+
> kubectl get cm --all -namespaces # get the config map in all namespaces
107
+
> kubectl get cm --all -namespaces -o yaml # get the config map in all namespaces in yaml format
108
+
> kubectl describe cm [configmap_name] # describe the given name config map
109
+
> kubectl describe cm --all-namespaces # describe the config map in all namespaces
110
+
> kubectl delete cm [configmap_name] # delete the given name config map
111
+
> kubectl delete cm --all # delete all the config map in current namespace
70
112
```
71
113
72
114
#### Logs
73
115
```bash
74
-
> kubectl logs [pod_name]
75
-
> kubectl logs [pod_name] -n=[namespace]
76
-
> kubectl logs --since=1h [pod_name]
77
-
> kubectl logs --tail=20 [pod_name]
78
-
> kubectl logs -f -c [container_name][pod_name]
79
-
> kubectl logs [pod_name] > pod.log
116
+
> kubectl logs [pod_name] # get the logs of the given pod name
117
+
> kubectl logs [pod_name] -n=[namespace] # get the logs of the given pod name in given namespace
118
+
> kubectl logs --since=1h [pod_name] # get the logs of the given pod name since one hour
119
+
> kubectl logs --tail=20 [pod_name] # get the last 20 lines of the logs of the given pod
120
+
> kubectl logs -f -c [container_name][pod_name] # begin the streaming of the logs of the given container name in the given pod name
121
+
> kubectl logs [pod_name] > pod.log # export the logs in pod.log of the given pod name
122
+
> kubectl logs [pod_name] --all-containers=true # get the pod has multi containers
123
+
> kubectl logs -l key=value --all-containers=true # get the logs from all containers have given label
124
+
> kubectl logs -p -c [container_name] [pod_name] # get the previous terminated logs in the given container name with the given pod name
125
+
> kubectl logs --insecure-skip-tls-verify-backend [pod_name] # show logs from a kubelet with an expired serving certificate
126
+
> kubectl logs job/[job_name] # get the logs with the given job name
127
+
> kubectl logs deployment/[deploy_name] -c [container_name] # get the logs from given container name of the given deployment name
80
128
```
81
129
82
130
#### Secrets
83
131
```bash
84
-
> kubectl get secrets
85
-
> kubeclt get secrets -n=[namespace]
86
-
> kubectl get secrets -n=[namespace] -o yaml
87
-
> kubectl get secrets --all -namespaces
88
-
> kubectl get secrets -o yaml
132
+
> kubectl get secrets # get the secrets in current namespace
133
+
> kubeclt get secrets -n=[namespace] # get the secrets in the given namespace
134
+
> kubectl get secrets -n=[namespace] -o yaml # get the secrets in the given namespace in yaml format
135
+
> kubectl get secrets --all -namespaces # get the secrets in all the namespaces
136
+
> kubectl get secrets -o yaml # get the secrets in current namespace in yaml format
137
+
> kubectl describe secret [secret_name] # describe the given secret name
138
+
> kubectl describe secret --all-namespaces # describe the secrets in all namespaces
139
+
> kubectl delete secret [secret_name] # delete the secret with given name
89
140
```
90
141
91
142
#### ReplicaSets
92
143
```bash
93
-
> kubectl get rs
94
-
> kubectl describe rs
95
-
> kubectl get rs -o wide
96
-
> kubectl get rs -o yaml
144
+
> kubectl get rs # get the replica sets in current namespace
145
+
> kubectl get rs -o wide # get the replica sets in wide format
146
+
> kubectl get rs -o yaml # get the replica sets in yaml format
147
+
> kubectl describe rs # describe all the replica sets
148
+
> kubectl describe rs --all-namespaces # describe the secrets in all namespaces
149
+
> kubectl describe rs [replicaset_name] # describe the given replica set name
150
+
> kubectl delete rs [replicaset_name] # delete the given replica set name
0 commit comments