liveBook · Manning

Imperative programming

As explained in Kubernetes in Action, Second Edition

An imperative command directly instructs a system to perform a specified operation.

Imperative programming gives a system direct commands for the operation it should perform. In Kubernetes, it offers a quick way to deploy an application without first writing a YAML or JSON manifest. section 3.3 section 3.3.1

The command kubectl create deployment creates a Deployment object with a chosen name and container image. Kubernetes stores that object in its API as the desired state, then works to make the running cluster match it. section 3.3.1

An imperative Kubernetes deployment typically involves these steps:

  • Choose the application name and container image. section 3.3.1
  • Run kubectl create deployment with those values. section 3.3.1
  • Inspect the Deployment or its Pods to see whether the application is ready. section 3.3.1
  • Use events and status information to follow scheduling, image pulling, container creation, and startup. section 3.3.1

Create a deployment

Run kubectl create deployment kiada --image=luksa/kiada:0.1. The command creates a Deployment named kiada and tells Kubernetes to run the specified image. Check progress with kubectl get deployments. section 3.3.1

$ kubectl create deployment kiada --image=luksa/kiada:0.1
deployment.apps/kiada created

The command output confirms that Kubernetes accepted the imperative request and created the Deployment object. section 3.3.1

How Kubernetes in Action, Second Edition covers it

How deep it goes
Explains command usage, desired state, status inspection, and startup events, but stops short of detailed manifest structure.
Examples
Uses kubectl create deployment with the Kiada application and inspects Deployment, Pod, and event output.
What it assumes
Assumes access to a Kubernetes cluster and a publicly pullable container image, while teaching deployment commands from the beginning.
What you can do after
Apply it via kubectl to create a Deployment and inspect whether its application becomes running.
How it connects
Connects imperative commands with declarative configuration, Kubernetes API objects, Deployments, Pods, container images, and desired state.

Also explained in

Compare how 14 books explain imperative programming →

Related concepts

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