This blog entry is part of the series of blogs to productionise a docker image in Kubernetes for enterprises. In our previous article, we saw a quick way of deploying Docker images to Kubernetes declaratively. In this entry, we will see a way of managing Kubernetes objects in a Minikube cluster using helm.

Minikube is a tool that runs a single-node Kubernetes cluster in a virtual machine on your personal computer. Deploying it in Minikube normally means you will be able to deploy your Docker images in most other versions of Kubernetes without many modifications.

For the sake of simplicity, we shall pick a couple of docker images from open libraries.

  • Mariadb is a community-developed fork of MySQL DB intended to remain free under the GNU GPL
  • PhpMyAdmin A web interface for MySQL and MariaDB administration. 

This is a quick way of a simulating an application stack with a 2-tier based web architecture and orchestration of multiple docker containers.

Helm is arguably the most famous package manager for Kubernetes resources. The closest analogies for Helm are Maven in Java world, Yum, Brew and apt-get. All of us must have used at least one of them and whoever has experienced a package manager will appreciate the ease of shareability and lifecycle management of the packages.

For Helm, there are three important concepts:

  1. The chart is a bundle of information necessary to create an instance of a Kubernetes application.
  2. The config contains configuration information that can be merged into a packaged chart to create a releasable object.
  3. release is a running instance of a chart, combined with a specific config.

There are loads of publicly available charts for MariaDB and Phpmyadmin but for the sake of this article, we will create a package using the YAMLs available here.

├── mariadb
│   ├── deployment.yaml
│   └── service.yaml
└── phpmyadmin
       ├── configmap.yaml
       ├── deployment.yaml
       └── service.yaml

Start Minikube

Start a quick single-node cluster

minikube start

Login to Docker

docker login

Install Helm by following the instructions here.

Package MariaDB

Create Chart.yaml

apiVersion: v2
name: mariadb
description: A Helm chart for Kubernetes

# A chart can be either an 'application' or a 'library' chart.
#
# Application charts are a collection of templates that can be packaged into versioned archives
# to be deployed.
#
# Library charts provide useful utilities or functions for the chart developer. They're included as
# a dependency of application charts to inject those utilities and functions into the rendering
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
type: application

# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
version: 0.1.0

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application.
appVersion: 1.16.0

Create a folder called templates and copy our deployment.yaml and service.yaml to this folder

mariadb/
├── Chart.yaml
└── templates
  ├── deployment.yaml
  └── service.yaml

Lint the chart to examine the chart for possible issues

helm lint mariadb/

==> Linting mariadb/
[INFO] Chart.yaml: icon is recommended
[INFO] values.yaml: file does not exist
1 chart(s) linted, 0 chart(s) failed

Package the chart to examine the chart for possible issues

helm package mariadb/

Successfully packaged chart and saved it to: /Users/thiru/git/aicloudpods/tutorials/helm/basic-1/mariadb-0.1.0.tgz

Package PhpMyAdmin

Create a folder phpmyadmin with Chart.yaml, create subfolder called templates and copy the configmap.yaml, service.yaml and deployment.yaml

phpmyadmin/
├── Chart.yaml
└── templates
  ├── configmap.yaml
  ├── deployment.yaml
  └── service.yaml

Lint the chart to examine the chart for possible issues

helm lint phpmyadmin/

==> Linting phpmyadmin/
[INFO] Chart.yaml: icon is recommended
[INFO] values.yaml: file does not exist
1 chart(s) linted, 0 chart(s) failed

Package the chart to examine the chart for possible issues

helm package phpmyadmin/

Successfully packaged chart and saved it to: /Users/thiru/git/aicloudpods/tutorials/helm/basic-1/phpmyadmin-0.1.0.tgz

Deploy Mariadb

Create a secret for storing the password for MariaDB root user.

kubectl create secret generic mariadb-secret --from-literal=root_pwd=changeit 

Let us do a dry-run to simulate an install against the cluster which will also do a basic semantic check with name conflicts

helm install mariadb mariadb-0.1.0.tgz --dry-run --debug

After sanity checking above, we could perform an install.

helm install mariadb mariadb-0.1.0.tgz

NAME: mariadb
LAST DEPLOYED: Sun May 24 16:14:39 2020
NAMESPACE: default
STATUS: deployed
REVISION: 1
TEST SUITE: None

Deploy PhpMyAdmin

Let us do a dry-run to simulate an install against the cluster which will also do a basic semantic check with name conflicts

helm install phpmyadmin phpmyadmin-0.1.0.tgz --dry-run --debug

After sanity checking above, we could perform an install.

helm install phpmyadmin phpmyadmin-0.1.0.tgz

NAME: phpmyadmin
LAST DEPLOYED: Sun May 24 16:14:55 2020
NAMESPACE: default
STATUS: deployed
REVISION: 1
TEST SUITE: None

Get the list of helm releases installed

helm list

NAME      	NAMESPACE	REVISION	UPDATED                             	STATUS  	CHART           	APP VERSION
mariadb   	default  	1       	2020-05-24 16:14:39.240828 +0100 BST	deployed	mariadb-0.1.0   	1.16.0
phpmyadmin	default  	1       	2020-05-24 16:14:55.431947 +0100 BST	deployed	phpmyadmin-0.1.0	1.16.0

Get the list of running deployments, pods, services and configmaps

kubectl get deployments,pods,svc,configmaps,secrets

NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/mariadb 0/1 1 0 48m
deployment.apps/phpmyadmin 0/1 1 0 48m

NAME READY STATUS RESTARTS AGE
pod/mariadb-b5b4685bf-lxz98 0/1 CreateContainerConfigError 0 48m
pod/phpmyadmin-d7988d9f9-vtqqg 0/1 CreateContainerConfigError 0 48m

NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/kubernetes ClusterIP 10.96.0.1 443/TCP 67m
service/mariadb ClusterIP 10.100.25.53 3306/TCP 48m
service/phpmyadmin LoadBalancer 10.96.154.200 8080:31436/TCP 48m

NAME DATA AGE
configmap/phpmyadmin-config 1 48m

NAME TYPE DATA AGE
secret/default-token-9bp76 kubernetes.io/service-account-token 3 67m

View the phpmyadmin service in browser using the below command

minikube service phpmyadmin

Login using ‘root’ as Username and ‘changeit’ as password. Click on the SQL tab and execute a sample query “select 1 from dual”, hit “Go” button to see results(as below). Also, this will prove end to end connectivity.

Delete the resources

helm uninstall mariadb
helm uninstall phpmyadmin
kubectl delete secret mariadb-secret

This is a quick way of packaging your kubernetes YAML resources as helm charts for sharing and deploying across the organisation. Helm offers a lot more features like templating, dependency management, etc., and we will explore each of them in future articles. We shall start by exploring templating in our next article.

Leave a Reply

Your email address will not be published. Required fields are marked *