Kubectl Commands For Beginners
$ kubectl config get-contexts
: View list of clusters
2. $ kubectl config current-context
: To view current running version
3. $ kubectl config use-context <context-name>
: Switch to cluster or context
4. $ kubectl get ns
: Generate a plain-text list of all namespaces
5. $ kubectl get po -A
: Generate list of all pods in all namespaces
6. $ kubectl create namespace [namespace-name]
: Create namespace
7. $kubectl get po
: Generate a plain-text list of all pods in default namespace.
$ kubectl get po -n <namespace_name>
: display pods underspecific name space
8. $ kubectl get pods -o wide
: Generate a detailed plain-text list of all pods, containing information such as node name
9. $ kubectl get svc
: Display all services in default namespace
10. $ kubectl create –f [manifest-filename]
:Create a resource from a JSON or YAML file
11. $ kubectl apply -f [manifest-file].yaml
: To apply or update a resource use the kubectl apply command. The source in this operation can be either a file or the standard input (stdin). Create a new service with the definition contained in [service-name].yaml
12. $ kubectl describe pods <pod-name>
: To display the state of any number of resources in detail, use the kubectl describe command. By default, the output also lists uninitialized resources. View details about a particular pods.
13. $ kubectl delete -f pod.yaml
: To remove resources from a file or stdin, use the kubectl delete command.Remove a pod using the name and type listed in pod.yaml
14. $ kubectl delete pods,services -l [label-key]=[label-value]
:Remove all pods and services with a specific label
15. kubectl exec -ti [pod-name] /bin/bash
: Run /bin/bash from a specific pod. The received output comes from the first container
16. kubectl logs -f [pod-name]
: To stream logs from a pod, use
17. Copy data from pod to the local machine:$kubectl cp <some-namespace>/<some-pod>:/tmp/foo /tmp/bar
and For copy data from local machine to pod:$kubectl cp /tmp/bar <some-namespace>/<some-pod>:/tmp/foo