Lab 2 - Update Application
In Lab 1, we installed the guestbook sample app by using Helm and saw the benefits over using kubectl
. You probably think that you're done and know enough to use Helm. But what about updates or improvements to the chart? How do you update your running app to pick up these changes?
In this lab, we're going to look at how to update our running app when the chart has been changed. To demonstrate this, we're going to make changes to the original guestbook
chart by:
Removing the Redis slaves and using just the in-memory DB
Changing the type from
LoadBalancer
toNodePort
.
It seems contrived but the goal of this lab is to show you how to update your apps with Kubernetes and Helm. So, how easy is it to do this? Let's take a look below.
Scenario 1: Update the application using kubectl
kubectl
In this part of the lab we will update the previously deployed application Guestbook, using Kubernetes directly.
This is an optional step that is not technically required to update your running app. The reason for doing this step is "house keeping" - you want to have the correct files for the current configuration that you have deployed. This avoids making mistakes if you have future updates or even rollbacks. In this updated configuration, we remove the Redis slaves. To have the directory match the configuration, move/archive or simply remove the Redis slave files from the guestbook repo tree:
Note: you can reclaim these files later with a
git checkout -- <filename>
command, if desiredDelete the Redis slave service and pods:
Update the guestbook service from
LoadBalancer
toNodePort
type:Note: you can reset the files later with a
git checkout -- <filename>
command, if desiredDelete the guestbook service:
Re-create the service with
NodePort
type:Check the updates, using
Note: The service type has changed (to
NodePort
) and a new port has been allocated (31989
in this output case) to the guestbook service. Allredis-slave
resources have been removed.View the guestbook
Get the public IP of one of your nodes:
Navigate to the IP address plus the node port that printed earlier.
Scenario 2: Update the application using Helm
In this section, we'll update the previously deployed guestbook-demo
application by using Helm.
Before we start, let's take a few minutes to see how Helm simplifies the process compared to using Kubernetes directly. Helm's use of a template language provides great flexibility and power to chart authors, which removes the complexity to the chart user. In the guestbook example, we'll use the following capabilities of templating:
Values: An object that provides access to the values passed into the chart. An example of this is in
guestbook-service
, which contains the linetype: {{ .Values.service.type }}
. This line provides the capability to set the service type during an upgrade or install.Control structures: Also called “actions” in template parlance, control structures provide the template author with the ability to control the flow of a template’s generation. An example of this is in
redis-slave-service
, which contains the line{{- if .Values.redis.slaveEnabled -}}
. This line allows us to enable/disable the REDIS master/slave during an upgrade or install.
The complete redis-slave-service.yaml
file shown below, demonstrates how the file becomes redundant when the slaveEnabled
flag is disabled and also how the port value is set. There are more examples of templating functionality in the other chart files.
Enough talking about the theory. Now let's give it a go!
First, lets check the app we deployed in Lab 1 with Helm. This can be done by checking the Helm releases:
Note that we specify the namespace. If not specified, it uses the current namespace context. You should see output similar to the following:
The
list
command provides the list of deployed charts (releases) giving information of chart version, namespace, number of updates (revisions) etc.We now know the release is there from step 1., so we can update the application:
A Helm upgrade takes an existing release and upgrades it according to the information you provide. You should see output similar to the following:
The
upgrade
command upgrades the app to a specified version of a chart, removes theredis-slave
resources, and updates the appservice.type
toNodePort
.Check the updates, using:
Note: The service type has changed (to
NodePort
) and a new port has been allocated (31202
in this output case) to the guestbook service. Allredis-slave
resources have been removed.When you check the Helm release with
helm list -n helm-demo
, you will see the revision and date has been updated:View the guestbook
Get the public IP of one of your nodes:
Navigate to the IP address plus the node port that printed earlier.
Conclusion
Congratulations, you have now updated the applications! Helm does not require any manual changing of resources and is therefore so much easier to upgrade! All configurations can be set on the fly on the command line or by using override files. This is made possible from when the logic was added to the template files, which enables or disables the capability, depending on the flag set.
Check out Lab 3 to get an insight into revision management.
Last updated