← Writing

Use Kubernetes locally — practice deployment, updates, and rollback with minikube

On this page

Start a local Kubernetes cluster with minikube and deploy two NGINX Pods. Check the HTTP response on localhost, update the image, then roll back and inspect the image tags assigned to the Pods at each stage. You can also use the same Deployment and Service to run a Spring Boot app.

Check Docker, start a dedicated profile, deploy NGINX and check HTTP, then update and roll back the image. Check the Pod image tags once the Pods are ready at each deployment stage.

Check Docker and start a practice cluster

You need minikube, a working Docker engine, Bash, and curl. First check that docker version shows a Server section. If it shows only Client or reports a connection error, check the Docker engine connection before continuing. Install minikube · Docker driver requirements

docker version

Use local-web as a new profile for this exercise. If the name is already in use, replace it with an unused name in every command. The exercise targets resources in the specified profile. The start command can change the current kubectl context. Add --keep-context to the start command if you need to keep it. The Bash function k routes each command to this profile. Check that k get nodes reports a node as Ready. minikube start · minikube kubectl

minikube start -p local-web --driver=docker
k() { minikube kubectl -p local-web -- "$@"; }
k get nodes

Deploy two NGINX Pods

Save the following as local-web.yaml. The Deployment maintains two Pods, and the readiness probe sends an HTTP request to / on the container port named http. The Service uses the default ClusterIP type and maps Service port 80 to the Pods’ http port. The Service’s metadata.labels let the listing command find it, while spec.selector picks the Pods that receive traffic. Deployment · Readiness probes

apiVersion: apps/v1
kind: Deployment
metadata:
  name: local-web
spec:
  replicas: 2
  selector:
    matchLabels:
      app: local-web
  template:
    metadata:
      labels:
        app: local-web
    spec:
      containers:
        - name: nginx
          image: nginx:1.30.0-alpine
          ports:
            - name: http
              containerPort: 80
          readinessProbe:
            httpGet:
              path: /
              port: http
---
apiVersion: v1
kind: Service
metadata:
  name: local-web
  labels:
    app: local-web
spec:
  selector:
    app: local-web
  ports:
    - port: 80
      targetPort: http
k apply -f local-web.yaml
k rollout status deployment/local-web --timeout=120s
k get pods,svc -l app=local-web

After the rollout completes, check that both Pods show 1/1 and the Service shows ClusterIP.

Check the HTTP response on localhost

Start port forwarding through the Service in the first terminal. While that command is running, send GET / from a second terminal.

k port-forward --address 127.0.0.1 service/local-web 18080:80
curl --fail --show-error http://127.0.0.1:18080/

The default NGINX page confirms that the selected Pod responds over HTTP. Port forwarding selects one Pod even when you specify a Service, so this check cannot verify load balancing. If the selected Pod terminates, restart port forwarding. Press Ctrl+C in the first terminal to stop forwarding before changing the image. kubectl port-forward

Update the image and roll back

First inspect the current image tags. After setting the new image, wait for the rollout to complete and inspect the Pods again. If old Pods are still terminating, check again after they disappear from the list.

k get pods -l app=local-web -o 'custom-columns=NAME:.metadata.name,IMAGE:.spec.containers[*].image'
k set image deployment/local-web nginx=nginx:1.30.1-alpine
k rollout status deployment/local-web --timeout=120s
k get pods -l app=local-web -o 'custom-columns=NAME:.metadata.name,IMAGE:.spec.containers[*].image'

Use rollout undo to return to the Deployment’s previous revision. After the rollout completes, check the two newly ready Pods.

k rollout undo deployment/local-web
k rollout status deployment/local-web --timeout=120s
k get pods -l app=local-web -o 'custom-columns=NAME:.metadata.name,IMAGE:.spec.containers[*].image'

The expected tags are 1.30.0-alpine → 1.30.1-alpine → 1.30.0-alpine. Read the Pods’ image fields for version checks. The default NGINX HTML cannot identify the image version.

When a rollout stalls

If rollout status times out, inspect Pod status and events. For ErrImagePull or ImagePullBackOff, check the tag, registry connectivity, and node architecture. If the image was pulled and the Pod is still unready, check the HTTP probe path and port reported by describe pod.

k get pods -l app=local-web
k describe deployment local-web
k describe pod -l app=local-web
k get events --sort-by=.metadata.creationTimestamp

Try the same workflow with a Spring Boot image

Build the image in the directory containing the Dockerfile from the Spring Boot Docker deployment guide, then load it into the profile. This example assumes the app listens on 8080 and Actuator’s default /actuator/health endpoint is enabled. minikube image load · Image pull policy

docker build -t spring-demo:local-1 .
minikube image load -p local-web spring-demo:local-1

Return to the directory containing local-web.yaml. Replace the existing item in spec.template.spec.containers in local-web.yaml with the item below. Keep Service port 80 and targetPort: http. The container port named http now points to 8080.

- name: spring-demo
  image: spring-demo:local-1
  imagePullPolicy: IfNotPresent
  ports:
    - name: http
      containerPort: 8080
  readinessProbe:
    httpGet:
      path: /actuator/health
      port: http

Reapply the manifest and wait for the rollout. Start port forwarding again in the first terminal. In a second terminal, check for UP in the health response and spring-deploy-demo at the example app URL.

k apply -f local-web.yaml
k rollout status deployment/local-web --timeout=120s
k port-forward --address 127.0.0.1 service/local-web 18080:80
curl --fail --show-error http://127.0.0.1:18080/actuator/health
curl --fail --show-error http://127.0.0.1:18080/

Use a fresh local-2 tag for the next build. After loading it, update the manifest’s image tag and press Ctrl+C to stop forwarding. Reapply the manifest, wait for the rollout, and check both URLs again.

docker build -t spring-demo:local-2 .
minikube image load -p local-web spring-demo:local-2

The local Docker deployment rehearsal walks through a similar image change with Compose. Use a production-like staging environment to verify the production Ingress, TLS, managed storage, and behavior during node failures.

Remove the practice profile

Press Ctrl+C if port forwarding is running, then delete only the profile created for this exercise.

minikube delete -p local-web

Verification scope

The official NGINX image tags on Docker Hub both listed Linux amd64 and arm64. The YAML selectors and port mappings were checked, and kubectl 1.27.2 with set image --local changed the image field in the manifest. The Docker engine was unavailable, so cluster startup, HTTP responses, actual Pod replacement, and rollback could not be run. The results above are expected outcomes. Official NGINX image tags

Discussion

View on GitHub ↗