Skip to content

Lesson 2: Updating the Kubechaos App

How do you update a running application without breaking it? In this lesson, we'll explore redeployment in Kubernetes by applying changes to both the application image and specification.

Step 1: Customise the Application

Open image/app.js and find the suprises variable (line 7). This is a JavaScript array where each element is a string with HTML content:

const surprises = [
  `<h2>🎯 Click the target!</h2>
   <div style="font-size:100px;cursor:pointer;" onclick="alert('You hit it! 🎉')">🎯</div>`,

  `<h2>😂 Joke of the moment</h2>
   <p>Why did the dolphin get a job in Kubernetes?<br>Because it already knew how to work in pods.</p>`,

  // ... more entries
];

Your tasks:

  1. Locate the "KubeChaos @ RSECon26!" title and replace it with "<your-name> @ RSECon26!"
  2. Remove the original surprise elements
  3. Add 2-3 of you own surprises with jokes or other HTML content

JavaScript Array Syntax

  • Each element is a multi-line string wrapped in backticks `
  • Successive elements are separated by commas

Building the New Image

Once you've made your changes, build a new container image with a v2 tag:

minikube image build -t local/kubechaos:v2 image

Verify your new image was created:

minikube image ls

You should see both local/kubechaos:v1 and local/kubechaos:v2 listed.

Step 2: Update and Redeploy

Now let's update your deployment to use the new image.

Update the manifest

Open deployment/manifests.yaml and update the image tag used by the container:

    spec:
      containers:
      - name: app
        image: local/kubechaos:v2  # Changed from v1

Make sure to save the file.

Redeploy the Application:

Apply your changes to the cluster:

kubectl apply -f deployment/manifests.yaml

Check when the deployment is complete:

kubectl rollout status deployment kubechaos

Tip

If we had simply modified and rebuilt the v1 image, it would have been sufficient to restart the deployment (kubectl rollout restart deploy kubechaos). Since we changed the manifest, however, a redeployment is necessary.

Test Your Changes

Return to the browser window/URL with the running application—on refresh you should now see your own jokes and custom title!

Info

If you closed the browser window, you can get the service URL from minikube service kubechaos-svc --url as before.

Undoing Rollouts

By default, Kubernetes retains memory of the last 3 revisions of a deployment If you've made a mistake, you can revert to the previous revision (in this case where image: lcoal/kubechaos:v1) with

kubectl rollout undo deployment kubechaos

If you want to view all revisions in the history:

kubectl rollout history deployment kubechaos

You can then inspect a particular revision like

kubectl rollout history deployment kubechaos --revision=2

and further rollback to that one with

kubectl rollout undo deployment kubechaos --to-revision=2

Tip

Specify a higher revisionHistoryLimit in the deployment manifest if you want to increase the number of revisions Kubernetes remembers.

📚 Further Reading