What is kubectl?
- Docker & Kubernetes course
- Intermediate
- Lesson 13/82
- 4 min
Learn that kubectl is the Kubernetes CLI.
What is kubectl?
kubectl is the command-line tool that sends requests to the Kubernetes API. Commands usually have the form kubectl VERB RESOURCE [NAME] [flags]:
kubectl get pods
kubectl describe deployment web
kubectl delete service web
kubectl logs pod/web-7c5b9f6d8-abcdeResource types have abbreviations: po (pods), deploy (deployments), svc (services), ns (namespaces), cm (configmaps).
kubeconfig and context
kubectl reads which cluster to connect to and with which user from the ~/.kube/config file (kubeconfig). Several contexts (cluster + user + namespace) can be kept in the file:
$ kubectl config get-contexts
CURRENT NAME CLUSTER AUTHINFO NAMESPACE
* minikube minikube minikube default
uretim uretim ali
$ kubectl config use-context uretim
$ kubectl config current-context
uretimPractice Which cluster are you on?
Write three commands: list the contexts; switch to the minikube context; print the active context.
Starter code
# buraya yazSample solution
kubectl config get-contexts
kubectl config use-context minikube
kubectl config current-contextExpected output
CURRENT NAME CLUSTER AUTHINFO NAMESPACE
minikube minikube minikube default
* uretim uretim ali
Switched to context "minikube".
minikube
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 What does kubectl get svc list?
- ServiceAccounts
- Servers
- Services Correct answer
- Secrets
Explanation: kubectl api-resources lists all types and their abbreviations.
2 Change the active context.
kubectl config ____ minikube
kubectl config use-context minikube
Explanation: use-context changes kubectl's target cluster.
3 Match the abbreviations.
| Term | Meaning |
|---|---|
po |
pods |
deploy |
deployments |
svc |
services |
cm |
configmaps |