Skip to content

Latest commit

 

History

History
95 lines (71 loc) · 3.26 KB

File metadata and controls

95 lines (71 loc) · 3.26 KB

Declarative Deployment

For this example we are using a Minikube installation for this example. For details, please refer to the installation instructions.

Let’s look at how we can get our random-generator application from version 1 to version 2 with different update strategies.

First, install the application in version 1 using the given deployment descriptor.

kubectl apply -f https://k8spatterns.io/DeclarativeDeployment/rolling-update.yml

This deployment will start three replicas of the random-generator and configures a RollingUpdate update strategy (which would also be the default).

To be able to access our application, let’s create a Service that is exposed with Minikube’s internal load balancer:

kubectl apply -f https://k8spatterns.io/DeclarativeDeployment/service.yml

The service is of type LoadBalancer, so to access this service, you need to tell minikube to expose this at a random port. To do this, run the following command in the background, storing the URL that is printed out in a temporary file:

minikube service random-generator --url > /tmp/random-url.txt &

Let’s start now in a dedicated terminal window, a loop that constantly accesses our service:

url=$(cat /tmp/random-url.txt)
while true; do
  curl -s $url/info | jq '.version,.id'
  echo "==========================="
  sleep 1
done

Now it’s time to update to version 2.0. As mentioned in the book, you can do it in several ways. Here we are using the easiest one and call kubectl set image:

kubectl set image deployment random-generator random-generator=k8spatterns/random-generator:2.0

After you start the deployment, you can do several things to monitor the update:

  • Watch the terminal with the query loop we started. Do you see the change from version 1 to version 2? Does curl report any errors?

  • Use kubectl get pods -w to watch how the Pods are coming down and up

  • Use kubectl rollout status to see the rollout status.

When the update has finished, let’s have some fun:

# Rollback the Deployment
kubectl rollout undo deploy/random-generator
# Check the update history
kubectl rollout history deploy/random-generator

Finally, let’s switch the update strategy to Recreate:

kubectl replace -f https://k8spatterns.io/DeclarativeDeployment/recreate.yml

# Update to version 2.0 (or change to 1.0 when you have 2.0 running)
kubectl set image deployment random-generator random-generator=k8spatterns/random-generator:2.0

Can you spot the difference when doing the update, also concerning the downtime?