Skip to content

Commit 101fd90

Browse files
committed
Create kubectl.md sheetcheat
Title correction to fit with the devhints.io template
1 parent 43fddd4 commit 101fd90

File tree

1 file changed

+41
-30
lines changed

1 file changed

+41
-30
lines changed

kubectl.md

Lines changed: 41 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,25 @@
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+
---
13+
114
## Getting started
215

316
### Kubectl Autocomplete
417

518
#### BASH
619

720
```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
21+
source <(kubectl completion bash) # setup autocomplete in bash into the current shell, bash-completion package should be installed first.
22+
echo "source <(kubectl completion bash)" >> ~/.bashrc # add autocomplete permanently to your bash shell.
1023
```
1124

1225
You can also use a shorthand alias for `kubectl` that also works with completion:
@@ -19,8 +32,8 @@ complete -F __start_kubectl k
1932
#### ZSH
2033

2134
```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
35+
source <(kubectl completion zsh) # setup autocomplete in zsh into the current shell
36+
echo "[[ $commands[kubectl] ]] && source <(kubectl completion zsh)" >> ~/.zshrc # add autocomplete permanently to your zsh shell
2437
```
2538

2639
### Kubectl Context and Configuration
@@ -244,7 +257,7 @@ kubectl scale --replicas=5 rc/foo rc/bar rc/baz # Scale multip
244257
### Deleting Resources
245258

246259
```bash
247-
kubectl delete -f ./pod.json # Delete a pod using the type and name specified in pod.json
260+
kubectl delete -f ./pod.json # Delete a pod using the type and name specified in pod.json
248261
kubectl delete pod,service baz foo # Delete pods and services with same names "baz" and "foo"
249262
kubectl delete pods,services -l name=myLabel # Delete pods and services with label name=myLabel
250263
kubectl -n my-ns delete pod,svc --all # Delete all pods and services in namespace my-ns,
@@ -254,28 +267,26 @@ kubectl get pods -n mynamespace --no-headers=true | awk '/pattern1|pattern2/{pr
254267

255268
### Interacting with running Pods
256269

257-
```bash
258-
kubectl logs my-pod # dump pod logs (stdout)
259-
kubectl logs -l name=myLabel # dump pod logs, with label name=myLabel (stdout)
260-
kubectl logs my-pod --previous # dump pod logs (stdout) for a previous instantiation of a container
261-
kubectl logs my-pod -c my-container # dump pod container logs (stdout, multi-container case)
262-
kubectl logs -l name=myLabel -c my-container # dump pod logs, with label name=myLabel (stdout)
263-
kubectl logs my-pod -c my-container --previous # dump pod container logs (stdout, multi-container case) for a previous instantiation of a container
264-
kubectl logs -f my-pod # stream pod logs (stdout)
265-
kubectl logs -f my-pod -c my-container # stream pod container logs (stdout, multi-container case)
266-
kubectl logs -f -l name=myLabel --all-containers # stream all pods logs with label name=myLabel (stdout)
267-
kubectl run -i --tty busybox --image=busybox -- sh # Run pod as interactive shell
268-
kubectl run nginx --image=nginx --restart=Never -n
269-
mynamespace # Run pod nginx in a specific namespace
270-
kubectl run nginx --image=nginx --restart=Never # Run pod nginx and write its spec into a file called pod.yaml
271-
--dry-run -o yaml > pod.yaml
272-
273-
kubectl attach my-pod -i # Attach to Running Container
274-
kubectl port-forward my-pod 5000:6000 # Listen on port 5000 on the local machine and forward to port 6000 on my-pod
275-
kubectl exec my-pod -- ls / # Run command in existing pod (1 container case)
276-
kubectl exec my-pod -c my-container -- ls / # Run command in existing pod (multi-container case)
277-
kubectl top pod POD_NAME --containers # Show metrics for a given pod and its containers
278-
```
270+
| Command | Description |
271+
| ------- | ----------- |
272+
| `kubectl logs my-pod` | dump pod logs (stdout) |
273+
| `kubectl logs -l name=myLabel` | dump pod logs, with label name=myLabel (stdout) |
274+
| `kubectl logs my-pod --previous` | dump pod logs (stdout) for a previous instantiation of a container |
275+
| `kubectl logs my-pod -c my-container` | dump pod container logs (stdout, multi-container case) |
276+
| `kubectl logs -l name=myLabel -c my-container` | dump pod logs, with label name=myLabel (stdout) |
277+
| `kubectl logs my-pod -c my-container --previous` | dump pod container logs (stdout, multi-container case) for a previous instantiation of a container |
278+
| `kubectl logs -f my-pod` | stream pod logs (stdout) |
279+
| `kubectl logs -f my-pod -c my-container` | stream pod container logs (stdout, multi-container case) |
280+
| `kubectl logs -f -l name=myLabel --all-containers` | stream all pods logs with label name=myLabel (stdout) |
281+
| `kubectl run -i --tty busybox --image=busybox -- sh` | Run pod as interactive shell |
282+
| `kubectl run nginx --image=nginx --restart=Never -n mynamespace` | Run pod nginx in a specific namespace |
283+
| `kubectl run nginx --image=nginx --restart=Never --dry-run -o yaml > pod.yaml` | Run pod nginx and write its spec into a file called pod.yaml |
284+
| `kubectl attach my-pod -i` | Attach to Running Container |
285+
| `kubectl port-forward my-pod 5000:6000` | Listen on port 5000 on the local machine and forward to port 6000 on my-pod |
286+
| `kubectl exec my-pod -- ls /` | Run command in existing pod (1 container case) |
287+
| `kubectl exec my-pod -c my-container -- ls /` | Run command in existing pod (multi-container case) |
288+
| `kubectl top pod POD_NAME --containers` | Show metrics for a given pod and its containers |
289+
279290

280291
### Interacting with Nodes and Cluster
281292

@@ -332,7 +343,7 @@ Examples using `-o=custom-columns`:
332343
# All images running in a cluster
333344
kubectl get pods -A -o=custom-columns='DATA:spec.containers[*].image'
334345

335-
# All images excluding "k8s.gcr.io/coredns:1.6.2"
346+
# All images excluding "k8s.gcr.io/coredns:1.6.2"
336347
kubectl get pods -A -o=custom-columns='DATA:spec.containers[?(@.image!="k8s.gcr.io/coredns:1.6.2")].image'
337348

338349
# All fields under metadata regardless of name
@@ -345,8 +356,8 @@ More examples in the kubectl [reference documentation](https://kubernetes.io/doc
345356

346357
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).
347358

348-
| Verbosity | Description |
349-
| ----------------------------------- | -------------------------------- |
359+
| Verbosity | Description |
360+
| --------- | ----------- |
350361
| `--v=0` | Generally useful for this to always be visible to a cluster operator. |
351362
| `--v=1` | A reasonable default log level if you don’t want verbosity. |
352363
| `--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. |

0 commit comments

Comments
 (0)