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 using imperative YAML/JSON files. In this entry, we will see a way of managing Kubernetes objects in a Minikube cluster declaratively.

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.

Deploying Declaratively

Keeping the configurations for objects in files enables easy CI/CD and easy replication across environments with source control. A detailed explanation of different ways of creating Kubernetes resources and their pros/cons is available here.

Start a quick single-node cluster

minikube start

Login to Docker

docker login

A Kubernetes Pod is a group of one or more Containers, tied together for the purposes of administration and networking.

A Kubernetes Deployment checks on the health of your Pod and restarts the Pod’s Container if it terminates. Deployments are the recommended way to manage the creation and scaling of Pods.

For the benefit of our exercise, we will stick to the model of one container per pod.

Deploy Mariadb And PhpMyAdmin

Create a secret for storing the password for MariaDB root user. Kubernetes Secrets let you store and manage sensitive information, such as passwords, OAuth tokens, and ssh keys. Storing confidential information in a Secret is safer and more flexible than putting it verbatim in a Pod definition or in a container image.

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

Clone YAML files from our repo

kubectl apply -R -f declarative/

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

kubectl delete deployment phpmyadmin
kubectl delete deployment mariadb
kubectl delete svc mariadb
kubectl delete svc phpmyadmin
kubectl delete secret mariadb-secret
kubectl delete configmap phpmyadmin-config

This is a quick way of getting your docker images deployed into Kubernetes. Many organisations tend to keep resource creation via YAML/JSONs and use for automation. But, as the number of Kubernetes resources increases and in an enterprise environment for shareability, a package manager like helm will be immensely helpful. We will see the packaging of these YAML/JSONs using helm in our next article.

Leave a Reply

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