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
Copy file name to clipboardExpand all lines: kubectl.md
+64-51Lines changed: 64 additions & 51 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,12 +1,26 @@
1
-
## Getting started
1
+
---
2
+
title: kubectl
3
+
category: kubernetes
4
+
layout: 2017/sheet
5
+
tags: [Featured]
6
+
updated: 2020-05-16
7
+
weight: -10
8
+
intro: |
9
+
Kubectl is a command line tool for controlling Kubernetes clusters. `kubectl` looks for a file named config in the $HOME/.kube directory. You can specify other [kubeconfig](https://kubernetes.io/docs/concepts/configuration/organize-cluster-access-kubeconfig/) files by setting the KUBECONFIG environment variable or by setting the [--kubeconfig](https://kubernetes.io/docs/concepts/configuration/organize-cluster-access-kubeconfig/) flag.
10
+
11
+
This overview covers kubectl syntax, describes the command operations, and provides common examples. For details about each command, including all the supported flags and subcommands, see the [kubectl](https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands/) reference documentation. For installation instructions see [installing kubectl](https://kubernetes.io/docs/tasks/kubectl/install/).
12
+
---
2
13
3
-
### Kubectl Autocomplete
14
+
Getting started
15
+
---------------
4
16
5
-
#### BASH
17
+
# Kubectl Autocomplete
18
+
19
+
## BASH
6
20
7
21
```bash
8
-
source<(kubectl completion bash)#active l'auto-complétion pour bash dans le shell courant, le paquet bash-completion devant être installé au préalable
9
-
echo"source <(kubectl completion bash)">>~/.bashrc #ajoute l'auto-complétion de manière permanente à votre shell bash
22
+
source<(kubectl completion bash)#setup autocomplete in bash into the current shell, bash-completion package should be installed first.
23
+
echo"source <(kubectl completion bash)">>~/.bashrc #add autocomplete permanently to your bash shell.
10
24
```
11
25
12
26
You can also use a shorthand alias for `kubectl` that also works with completion:
@@ -16,14 +30,14 @@ alias k=kubectl
16
30
complete -F __start_kubectl k
17
31
```
18
32
19
-
####ZSH
33
+
## ZSH
20
34
21
35
```zsh
22
-
source<(kubectl completion zsh)#active l'auto-complétion pour zsh dans le shell courant
23
-
echo"if [$commands[kubectl] ]; then source <(kubectl completion zsh); fi">>~/.zshrc #ajoute l'auto-complétion de manière permanente à votre shell zsh
36
+
source<(kubectl completion zsh)#setup autocomplete in zsh into the current shell
37
+
echo"[[$commands[kubectl] ]] && source <(kubectl completion zsh)">>~/.zshrc #add autocomplete permanently to your zsh shell
24
38
```
25
39
26
-
###Kubectl Context and Configuration
40
+
# Kubectl Context and Configuration
27
41
28
42
Set which Kubernetes cluster `kubectl` communicates with and modifies configuration information. See [Authenticating Across Clusters](https://kubernetes.io/docs/tasks/access-application-cluster/configure-access-multiple-clusters/) with kubeconfig documentation for detailed config file information.
`apply` manages applications through files defining Kubernetes resources. It creates and updates resources in a cluster through running `kubectl apply`. This is the recommended way of managing Kubernetes applications on production. See [Kubectl Book](https://kubectl.docs.kubernetes.io/).
63
77
64
-
###Creating Objects
78
+
# Creating Objects
65
79
66
80
Kubernetes manifests can be defined in YAML or JSON. The file extension `.yaml`, `.yml`, and `.json` can be used.
67
81
@@ -113,7 +127,7 @@ data:
113
127
EOF
114
128
```
115
129
116
-
###Viewing, Finding Resources
130
+
# Viewing, Finding Resources
117
131
118
132
```bash
119
133
# Get commands with basic output
@@ -177,7 +191,7 @@ kubectl get events --sort-by=.metadata.creationTimestamp
177
191
kubectl diff -f ./my-manifest.yaml
178
192
```
179
193
180
-
###Updating Resources
194
+
# Updating Resources
181
195
182
196
```bash
183
197
kubectl set image deployment/frontend www=image:v2 # Rolling update "www" containers of "frontend" deployment, updating the image
|`kubectl logs -l name=myLabel -c my-container`| dump pod logs, with label name=myLabel (stdout) |
278
+
|`kubectl logs my-pod -c my-container --previous`| dump pod container logs (stdout, multi-container case) for a previous instantiation of a container |
279
+
|`kubectl logs -f my-pod`| stream pod logs (stdout) |
List all supported resource types along with their shortnames, [API group](https://kubernetes.io/docs/concepts/overview/kubernetes-api/#api-groups), whether they are [namespaced](https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces), and [Kind](https://kubernetes.io/docs/concepts/overview/working-with-objects/kubernetes-objects):
298
310
@@ -311,7 +323,7 @@ kubectl api-resources --verbs=list,get # All resources that support the "l
311
323
kubectl api-resources --api-group=extensions # All resources in the "extensions" API group
312
324
```
313
325
314
-
####Formatting output
326
+
## Formatting output
315
327
316
328
To output details to your terminal window in a specific format, add the `-o` (or `--output`) flag to a supported `kubectl` command.
317
329
@@ -332,7 +344,7 @@ Examples using `-o=custom-columns`:
332
344
# All images running in a cluster
333
345
kubectl get pods -A -o=custom-columns='DATA:spec.containers[*].image'
334
346
335
-
# All images excluding "k8s.gcr.io/coredns:1.6.2"
347
+
# All images excluding "k8s.gcr.io/coredns:1.6.2"
336
348
kubectl get pods -A -o=custom-columns='DATA:spec.containers[?(@.image!="k8s.gcr.io/coredns:1.6.2")].image'
337
349
338
350
# All fields under metadata regardless of name
@@ -341,12 +353,12 @@ kubectl get pods -A -o=custom-columns='DATA:metadata.*'
341
353
342
354
More examples in the kubectl [reference documentation](https://kubernetes.io/docs/reference/kubectl/overview/#custom-columns).
343
355
344
-
####Kubectl output verbosity and debugging
356
+
## Kubectl output verbosity and debugging
345
357
346
358
Kubectl verbosity is controlled with the `-v` or `--v` flags followed by an integer representing the log level. General Kubernetes logging conventions and the associated log levels are described [here](https://github.com/kubernetes/community/blob/master/contributors/devel/sig-instrumentation/logging.md).
|`--v=0`| Generally useful for this to always be visible to a cluster operator. |
351
363
|`--v=1`| A reasonable default log level if you don’t want verbosity. |
352
364
|`--v=2`| Useful steady state information about the service and important log messages that may correlate to significant changes in the system. This is the recommended default log level for most systems. |
@@ -357,7 +369,8 @@ Kubectl verbosity is controlled with the `-v` or `--v` flags followed by an inte
357
369
|`--v=8`| Display HTTP request contents. |
358
370
|`--v=9`| Display HTTP request contents without truncation of contents. |
0 commit comments