liveBook · Manning

Kubectl

As explained in Acing the Certified Kubernetes Administrator Exam, Second Edition

kubectl is the Kubernetes command-line tool for interacting with Kubernetes clusters and their API objects.

kubectl is the command-line tool for working with Kubernetes API objects. With a valid certificate in kubeconfig and the necessary role-based access, it can create, read, update, and delete resources. Run `kubectl api-resources` to see which resource types a cluster exposes. section 1.4

Choose the command to match the intended change:

  • `kubectl create -f my-pod-manifest.yaml` creates a resource and errors if it already exists. section 1.9
  • `kubectl apply -f my-pod-manifest.yaml` creates or updates a resource toward the state described in YAML. section 1.9
  • `kubectl replace -f my-pod-manifest.yaml` replaces the resource; replacing a Deployment triggers a new rollout. section 1.9
apiVersion: v1
kind: Pod
metadata:
  labels:
    run: nginx
  name: nginx
spec:
  containers:
  - image: nginx
    name: nginx

This Pod manifest specifies an nginx container. Save it as `my-pod-manifest.yaml` to use with the create or apply commands above. section 1.9

Inspect and verify a cluster change

For a Service CIDR change, `kubectl get servicecidr` shows the current range; run it again after the change to check the new range. `kubectl get svc -A` then lists Services across namespaces so their assigned cluster IPs can be checked. Use `-n kube-system` when a command must target that namespace. section 6.1

For CKA tasks, check which cluster the question targets before acting. The exam environment provides `k` as an alias for `kubectl`; autocomplete and careful copying help avoid mistakes in long resource names. section 1.1 section 6.1

How Acing the Certified Kubernetes Administrator Exam, Second Edition covers it

How deep it goes
Explains resource discovery and manifest commands, then uses inspection and verification commands in a DNS configuration procedure.
Examples
Shows an nginx Pod manifest, create output, and Service CIDR and Service queries during DNS configuration.
What it assumes
Introduces kubectl as the cluster access tool and identifies the certificate needed for authentication.
What you can do after
Operate/configure Kubernetes resources with kubectl, choosing create, apply, or replace and checking resulting cluster state.
How it connects
Connects kubectl to the Kubernetes API, kubeconfig certificates, role-based access control, YAML manifests, and declarative configuration.

Also explained in

Compare how 11 books explain kubectl →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Acing the Certified Kubernetes Administrator Exam, Second Edition. The section links point to the parts of the book it draws on.