In this article I will describe how you can use Helm, the package manager for Kubernetes, to install two versions of a RESTful Web Service Spring Boot application, together with an external MySQL database, within Minikube.

Minikube

Minikube is a tool that makes it easy to run Kubernetes locally. Minikube runs a single-node Kubernetes cluster for users looking to try out Kubernetes or develop with it day-to-day.

Helm

Helm is the package manager for Kubernetes.With Helm you can find, share, and use software built for Kubernetes.

Helm helps you manage Kubernetes applications — Helm Charts help you define, install, and upgrade even the most complex Kubernetes application.Charts are easy to create, version, share, and publish — so start using Helm and stop the copy-and-paste.The latest version of Helm is maintained by the CNCF – in collaboration with Microsoft, Google, Bitnami and the Helm contributor community.

With Helm a team can:

Manage Complexity

Charts describe even the most complex apps, provide repeatable application installation, and serve as a single point of authority.

Easy Updates

Take the pain out of updates with in-place upgrades and custom hooks.

Simple Sharing

Charts are easy to version, share, and host on public or private servers.

Rollbacks

Use helm rollback to roll back to an older version of a release with ease.

Using Helm

The following prerequisites are required for a successful and properly secured use of Helm.

A Kubernetes cluster

You must have Kubernetes installed or have access to a cluster. You should also have a local configured copy of kubectl. In my case I am using Minikube.

Deciding what security configurations to apply to your installation, if any.

If you’re using Helm on a cluster that you completely control, like Minikube or a cluster on a private network in which sharing is not a concern, the default installation – which applies no security configuration – is fine, and it’s definitely the easiest. To install Helm without additional security steps, install Helm and then initialize Helm. Again, in my case I am using Minikube.

Installing and configuring Helm and Tiller, the cluster-side service.

There are two parts to Helm: The Helm client (helm) and the Helm server (Tiller).

Installing Helm

Installing Tiller

Tiller, the server portion of Helm, typically runs inside of your Kubernetes cluster. But for development, it can also be run locally, and configured to talk to a remote Kubernetes cluster.

The easiest way to install Tiller into the cluster is simply to run helm init. This will validate that Helm’s local environment is set up correctly (and set it up if necessary). Then it will connect to whatever cluster kubectl connects to by default (kubectl config view). Once it connects, it will install Tiller into the kube-system namespace.

Helm charts

Helm uses a packaging format called charts. A chart is a collection of files that describe a related set of Kubernetes resources. A single chart might be used to deploy something simple, like a memcached pod, or something complex, like a full web app stack with HTTP servers, databases, caches, and so on.

Charts are created as files laid out in a particular directory tree, then they can be packaged into versioned archives to be deployed.

The Chart File StructureA chart is organized as a collection of files inside of a directory. The directory name is the name of the chart (without versioning information). Thus, a chart describing WordPress would be stored in the wordpress/ directory.

Validating a chart

This command takes a path to a chart and runs a series of tests to verify that the chart is well-formed.If the linter encounters things that will cause the chart to fail installation, it will emit [ERROR] messages. If it encounters issues that break with convention or recommendation, it will emit [WARNING] messages.[https://helm.sh/docs/helm/#helm-lint]

Socat is a command line based utility that establishes two bidirectional byte streams and transfers data between them. Because the streams can be constructed from a large set of different types of data sinks and sources (see address types), and because lots of address options may be applied to the streams, socat can be used for many different purposes.[http://www.dest-unreach.org/socat/doc/socat.html]

When we take a look at the output of the simulation of installing the helm charts, we can see that the releases get a generated name. For example, with the simulation of installing the namespace-chart helm chart, the release is named: newbie-dingo.

By default, it lists only releases that are deployed or failed. Flags like ‘–deleted’ and ‘–all’ will alter this behavior. Such flags can be combined: ‘–deleted –failed’.By default, items are sorted alphabetically. Use the ‘-d’ flag to sort by release date.[https://helm.sh/docs/helm/#helm-list]

Next, we should be able to see our updated list at the /books path with a GET request. First I tried the service IP address:

curl http://10.105.241.75:9191/books
[{"id":"1","title":"The Threat: How the FBI Protects America in the Age of Terror and Trump","author":"Andrew G. McCabe","type":"Hardcover","price":17.99,"numOfPages":288,"language":"English","isbn13":"978-1250207579"},{"id":"2","title":"Becoming","author":"Michelle Obama","type":"Hardcover","price":17.88,"numOfPages":448,"language":"English","isbn13":"978-1524763138"}]

I also tried, the first Pod IP address:

curl http://172.17.0.11:9091/books
[{"id":"1","title":"The Threat: How the FBI Protects America in the Age of Terror and Trump","author":"Andrew G. McCabe","type":"Hardcover","price":17.99,"numOfPages":288,"language":"English","isbn13":"978-1250207579"},{"id":"2","title":"Becoming","author":"Michelle Obama","type":"Hardcover","price":17.88,"numOfPages":448,"language":"English","isbn13":"978-1524763138"}]

And then I tried, the second Pod IP address:

curl http://172.17.0.12:9091/books
[{"id":"1","title":"The Threat: How the FBI Protects America in the Age of Terror and Trump","author":"Andrew G. McCabe","type":"Hardcover","price":17.99,"numOfPages":288,"language":"English","isbn13":"978-1250207579"},{"id":"2","title":"Becoming","author":"Michelle Obama","type":"Hardcover","price":17.88,"numOfPages":448,"language":"English","isbn13":"978-1524763138"}]

Remember, this deployment uses the booksservice (RESTful Web Service Spring Boot Application) with an external MySQL database, running in a separate Docker container. So, the first and second Pod both use the same external MySQL database. Therefor it doesn’t matter to which Pod the service sent the POST-requests. Each of the above GET-requests responds with the same answer (all 2 books).

As a final step I checked the contents of the book table. Again I used a mysql-client for this.

Remark: This deployment uses the booksservice (RESTful Web ServiceSpring Boot application) with H2 as an embedded in-memory database. The replicas are set to 5, so the ReplicaSet ensures that 5 pod replicas are running at any given time. The ReplicaSet manages all the pods with labels that match the selector. In my case these labels are:

Label key

Label value

app

booksservice

version

2.0

environment

development

Via the Environment variables, the active Spring profile has to be set up.

Then, I updated the version of the release in the Chart.yaml file of the booksservice-chart helm chart to 0.2.0 The file Chart.yaml then has the following content:

By default, it lists only releases that are deployed or failed. Flags like ‘–deleted’ and ‘–all’ will alter this behavior. Such flags can be combined: ‘–deleted –failed’.Flag: –all show all releases, not just the ones marked DEPLOYED[https://helm.sh/docs/helm/#helm-list]

About Author

Marc, active in IT (and with Oracle) since 1995, is a Principal Oracle SOA Consultant with focus on Oracle Cloud, Oracle Service Bus, Oracle SOA Suite, Oracle Database (SQL & PL/SQL) and Java, Docker, Kubernetes, Minikube and Helm. He's Oracle SOA Suite 12c Certified Implementation Specialist. Over the past 20 years he has worked for several customers in the Netherlands. Marc likes to share his knowledge through publications, blog’s and presentations.

About Author

Marc Lameriks

Marc, active in IT (and with Oracle) since 1995, is a Principal Oracle SOA Consultant with focus on Oracle Cloud, Oracle Service Bus, Oracle SOA Suite, Oracle Database (SQL & PL/SQL) and Java, Docker, Kubernetes, Minikube and Helm. He's Oracle SOA Suite 12c Certified Implementation Specialist. Over the past 20 years he has worked for several customers in the Netherlands. Marc likes to share his knowledge through publications, blog’s and presentations.