liveBook · Manning

Kubectl

As explained in Developer Experience on Kubernetes

kubectl is the command-line client for interacting with the Kubernetes API and managing resources in Kubernetes clusters.

kubectl is the Kubernetes command-line client for working with a cluster through its API. In a local inner loop, it is configured to target the current kind cluster, then used to verify cluster state and manage application resources. section 3.3.1 section 3.3.3

A practical kubectl workflow is:

  • Confirm which cluster the CLI targets with `kubectl config current-context`; switch to `kind-devex-cluster` when needed. section 3.3.1
  • Check cluster capacity with `kubectl get nodes`; the local cluster shown has one ready control-plane node. section 3.3.1
  • Apply YAML manifests with `kubectl apply -f`, first for the PostgreSQL Cluster and then for application configuration. section 3.3.3
  • Inspect the deployed application resources by label with `kubectl get all -l app=appointments`, and remove configuration with `kubectl delete -f config`. section 3.3.3

Manifests declare the resources kubectl asks the API to create. A deployable application commonly needs a Deployment for replicated Pods, a Service for in-cluster networking, and an Ingress for external access; ConfigMaps and Secrets can supply configuration and credentials. section 3.3.3

Deploying the Appointments service

Build a local image, load it into the kind cluster, and run `kubectl apply -f config`. The resulting Deployment runs the Appointments container, while related manifest resources expose it and connect it to the provisioned PostgreSQL database. Query `kubectl get all -l app=appointments` to confirm the labeled resources. section 3.3.3

Listing 3.1 Deployment configuration for a cloud native application.
apiVersion: apps/v1
kind: Deployment
metadata:
  name: appointments #A
  labels:
    app: appointments
spec:
  selector:
    matchLabels:
      app: appointments
  template:
    metadata:
      labels:
        app: appointments
    spec:
      containers:
        - name: appointments #B
          image: ko.local/appointments:0.0.1-SNAPSHOT #C
          env: #D
            - name: POSTGRES_HOST
              valueFrom:
                secretKeyRef:
                  name: db-appointments-app
                  key: host
            - name: POSTGRES_PORT
              valueFrom:
                secretKeyRef:
                  name: db-appointments-app
                  key: port
            - name: POSTGRES_DB
              valueFrom:
                secretKeyRef:
                  name: db-appointments-app
                  key: dbname
            - name: POSTGRES_USERNAME
              valueFrom:
                secretKeyRef:
                  name: db-appointments-app
                  key: username
            - name: POSTGRES_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: db-appointments-app
                  key: password
          ...

The Deployment manifest shows the declared container image and environment values that kubectl submits as a Kubernetes resource. section 3.3.3

How Developer Experience on Kubernetes covers it

How deep it goes
Demonstrates context selection, node inspection, manifest application, label-based queries, and deletion without detailing kubectl internals.
Examples
Uses a kind-devex-cluster and the Appointments service with PostgreSQL, Deployment manifests, and `app=appointments` resource queries.
What it assumes
Assumes a provisioned local Kubernetes cluster while showing how to verify and select its current kubectl context.
What you can do after
Operate/configure it to select a local cluster, apply manifests, inspect labeled resources, and delete deployed configuration.
How it connects
Connects kubectl to Kubernetes API, YAML manifests, kind, Deployments, Pods, Services, Ingresses, ConfigMaps, Secrets, and CloudNativePG.

Also explained in

Compare how 12 books explain kubectl →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Developer Experience on Kubernetes. The section links point to the parts of the book it draws on.