Skip to main content
This hands-on lab practices imperative kubectl commands to create and inspect Kubernetes objects. These commands are useful for quick tasks and are commonly asked about in certification exams. Work through each step in order, run the commands shown, and use the verification steps to confirm resources are created and configured correctly. Helpful links and references:

1) Deploy a Pod named nginx-pod using the nginx:alpine image

Create a simple standalone Pod with kubectl run:
Expected output:
Verify the Pod exists:
You can inspect the Pod YAML to confirm image and other spec details:

2) Deploy a Redis Pod using the redis:alpine image with label tier=db

Add labels during creation with --labels:
Expected output:
Verify the label is present:
Inspect YAML to see the label in the Pod metadata:

3) Create a ClusterIP Service named redis-service to expose Redis on port 6379

There are two primary imperative approaches for creating Services:
  • kubectl create service clusterip — useful when you need explicit settings like --tcp mappings or a custom --clusterip. It does not infer selectors from pods automatically.
  • kubectl expose — creates a Service based on an existing resource (pod, deployment, etc.) and infers selectors from that object’s labels. This is usually the preferred approach when exposing an existing labeled object.
Use kubectl expose when you want the Service to automatically use the source object’s labels as the selector. Use kubectl create service when you need explicit control (for example, custom --clusterip or --node-port).
Because the redis Pod has the label tier=db, expose it as a ClusterIP Service named redis-service on port 6379:
Expected output:
Verify the Service:
Example kubectl get svc output:
Example kubectl describe svc redis-service (relevant fields):

4) Create a Deployment named webapp with 3 replicas

Use kubectl create deployment and set the number of replicas:
Expected output:
Verify the Deployment and its Pods:
Example kubectl get deployment output:
Tip: If the Deployment doesn’t become fully available immediately, give the cluster a few seconds and re-run kubectl get pods to see the rollout progress.

5) Create a Pod custom-nginx using the nginx image and set the container port to 8080

Set the container’s port with --port (this populates containerPort in the Pod spec):
Expected output:
Verify the port is set in the Pod spec:

6) Create a new namespace devns

Create and verify the namespace:
Expected output:
Verify:
When running commands in a specific namespace, either include -n <namespace> or set the namespace in your current context with kubectl config set-context --current --namespace=<namespace>.

7) Create a Deployment redis-deploy in namespace devns with 2 replicas

Create the Deployment in the devns namespace and set replicas to 2:
Expected output:
Verify the Deployment and Pods in the namespace:
Example output:

8) Create a Pod httpd (image: httpd:alpine) and a ClusterIP Service of the same name targeting port 80, using the fewest steps

Create both the Pod and a ClusterIP Service in one command by using --expose with kubectl run. --expose creates a ClusterIP service by default and requires --port:
Expected output:
Verify:
Example kubectl describe svc httpd (relevant fields):

Summary command reference


That completes the imperative tasks. Use kubectl get, kubectl describe, and kubectl get -o yaml to inspect resources and confirm labels, selectors, ports, and endpoints for each created object. If a pod or deployment takes time to become ready, wait a few moments and re-run the verification commands.

Watch Video