Summary - kubectl
- Docker & Kubernetes course
- Intermediate
- Lesson 18/82
- 5 min
Combine get, describe, apply and delete to manage resources.
Summary: kubectl
In this group:
- Command form:
kubectl VERB RESOURCE [NAME] [flags]; abbreviations: po, deploy, svc, ns, cm. - kubeconfig contexts select cluster/user/namespace (
config use-context). get(-o wide/yaml/name/jsonpath) lists;describegives a summary and events;explaingives field docs.apply -fdeclaratively creates/updates;diffand--dry-runcheck first.deletedeletes by name, file or label.
kubectl create deployment api --image=api:1.0 --dry-run=client -o yaml > api.yaml
kubectl apply -f api.yaml
kubectl describe deploy apiPractice A kubectl workflow
Write four commands: generate the YAML of an api deployment with the api:1.0 image into api.yaml without creating it; apply the file; show the api deployment in detail; list the pod names with -o name.
Starter code
# buraya yazSample solution
kubectl create deployment api --image=api:1.0 --dry-run=client -o yaml > api.yaml
kubectl apply -f api.yaml
kubectl describe deploy api
kubectl get pods -o nameExpected output
deployment.apps/api created Name: api Replicas: 1 desired | 1 updated | 1 total | 1 available pod/api-5d8f7c9b4-qrstu
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 What is the first place to look to understand why a pod stays Pending?
- The kubeconfig file
- The Events in the kubectl describe pod output Correct answer
- kubectl get nodes
- kubectl version
Explanation: The scheduler reports why it couldn't place it in an event.
2 Create or update the objects in the file.
kubectl ____ -f api.yaml
kubectl apply -f api.yaml
Explanation: apply is declarative.
3 Match.
| Term | Meaning |
|---|---|
get |
List |
describe |
Details |
apply |
Apply |
delete |
Delete |