CodeBlanks Logo Icon CodeBlanks

Summary - kubectl

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; describe gives a summary and events; explain gives field docs.
  • apply -f declaratively creates/updates; diff and --dry-run check first.
  • delete deletes 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 api

Practice 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

terminal
# buraya yaz

Sample solution

terminal
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 name

Expected 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.

Question
kubectl ____ -f api.yaml
Answer
kubectl apply -f api.yaml

Explanation: apply is declarative.

3 Match.

Term Meaning
get List
describe Details
apply Apply
delete Delete

All lessons in Intermediate