Note: If you have missed my previous articles on Docker and Kubernetes, you can find them here:
Application deployment models evolution.
Getting started with Docker.Docker file and images.
Publishing images to Docker Hub and re-using them.
Docker- Find out what's going on.
Docker Networking- Part 1.
Docker Networking- Part 2.
Docker Swarm-Multi-Host container Cluster.Docker Networking- Part 3 (Overlay Driver).
Introduction to Kubernetes.Kubernetes- Diving in (Part 1)-Installing Kubernetes multi-node cluster.
Kubernetes-Diving in (Part2)- Services.
Kubernetes- Infrastructure As Code with Yaml (part 1).
Kubernetes- Infrastructure As Code Part 2- Creating PODs with YAML.
Kubernetes Infrastructure-as-Code part 3- Replicasets with YAML.
Kubernetes Infrastructure-as-Code part 4 - Deployments and Services with YAML.
Deploying a microservices APP with Kubernetes.
Kubernetes- Time based scaling of deployments with python client.
Kubernetes Networking - The Flannel network explained.
Kubernetes- Installing and using kubectl top for monitoring nodes and PoDs
Kubernetes Administration- Scheduling
Kubernetes Administration- Storage
Kubernetes Administration- Users
Kubernetes Administration - Network Policies with Calico network plugin
Kubernetes Administration Managing Kubernetes Clusters with Rancher
Microservices-based applications deployed with Kubernetes are made up of multiple components like Pods, Replicasets, Deployments, Services, Statefulsets, etc. Each of these components can be defined, deployed with YAML files. Consider a widely deployed application like WordPress- WordPress deployment would be made up of multiple YAML files which need to be deployed individually. Further, if you are running multiple environments like Dev, QA, and production each of these might use different versions of components or use different deployment methods (local vs cloud). Maintaining YAML files for the WordPress app becomes a nightmare. Enter Helm!!
Helm is a package manager for Kubernetes. Helm can be used to package YAML files and distribute them to private/public repositories from where these can be re-used. These bundles of YAML files are called Helm Charts. Once pushed to a repository these Helm charts can be re-used. A public Helm repository is https://artifacthub.io/
Private repositories can be created for the distribution of Helm charts within an organization and is used with CI/CD pipelines involving multiple environments like dev, qa, production etc.
Installing Helm
Installation of Helm is quite simple and is described here. In my case, I just choose to install from apt-package manager as I am using Ubuntu.
curl https://baltocdn.com/helm/signing.asc | sudo apt-key add -
sudo apt-get install apt-transport-https --yes
echo "deb https://baltocdn.com/helm/stable/debian/ all main" | sudo tee /etc/apt/sources.list.d/helm-stable-debian.list
sudo apt-get update
sudo apt-get install helm
Installing WordPress with Helm
Installing WordPress with Helm is a simple 2 step process
Search for the package:
root@sathish-vm2:/home/sathish# helm search hub wordpress
URL CHART VERSION APP VERSION DESCRIPTION
https://artifacthub.io/packages/helm/bitnami/wo... 10.6.9 5.6.2 Web publishing platform for building blogs and ...
https://artifacthub.io/packages/helm/groundhog2... 0.2.9 5.6.2-apache A Helm chart for Wordpress on Kubernetes
https://artifacthub.io/packages/helm/seccurecod... 2.4.0 4.0 Insecure & Outdated Wordpress Instance: Never e...
https://artifacthub.io/packages/helm/presslabs/... 0.10.5 0.10.5 Presslabs WordPress Operator Helm Chart
https://artifacthub.io/packages/helm/presslabs/... 0.10.4 v0.10.4 A Helm chart for deploying a WordPress site on ...
https://artifacthub.io/packages/helm/gh-shessel... 1.0.3 5.6.1 Web publishing platform for building blogs and ...
https://artifacthub.io/packages/helm/seccurecod... 2.4.0 latest A Helm chart for the WordPress security scanner...
https://artifacthub.io/packages/helm/presslabs/... 0.10.4 v0.10.4 Open-Source WordPress Infrastructure on Kubernetes
Deploy WordPress with Helm Charts available in the public repository
# Add repository to helm and update helm repo
root@sathish-vm2:/home/sathish# helm repo add bitnami https://charts.bitnami.com/bitnami
"bitnami" has been added to your repositories
root@sathish-vm2:/home/sathish# helm repo update
Hang tight while we grab the latest from your chart repositories...
...Successfully got an update from the "bitnami" chart repository
Update Complete. ⎈Happy Helming!⎈
# Install wordpress
root@sathish-vm2:/home/sathish# helm install sathish-blog-prod bitnami/wordpress
NAME: sathish-blog-prod
LAST DEPLOYED: Sun Feb 28 12:29:43 2021
NAMESPACE: default
STATUS: deployed
REVISION: 1
NOTES:
** Please be patient while the chart is being deployed **
Your WordPress site can be accessed through the following DNS name from within your cluster:
sathish-blog-prod-wordpress.default.svc.cluster.local (port 80)
To access your WordPress site from outside the cluster follow the steps below:
1. Get the WordPress URL by running these commands:
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
Watch the status with: 'kubectl get svc --namespace default -w sathish-blog-prod-wordpress'
export SERVICE_IP=$(kubectl get svc --namespace default sathish-blog-prod-wordpress --template "{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}")
echo "WordPress URL: http://$SERVICE_IP/"
echo "WordPress Admin URL: http://$SERVICE_IP/admin"
2. Open a browser and access WordPress using the obtained URL.
3. Login with the following credentials below to see your blog:
echo Username: user
echo Password: $(kubectl get secret --namespace default sathish-blog-prod-wordpress -o jsonpath="{.data.wordpress-password}" | base64 --decode)
Templating with Helm
By default, the WordPress helm chart deploys a loadbalancer service type. Now, this will not work in my environment as I am running Kubernetes in a VM. I would want to run WordPress as NodePort service.
root@sathish-vm2:/home/sathish# kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 136d
my-webservice NodePort 10.103.164.119 <none> 80:30007/TCP 72d
mynginx ClusterIP 10.101.63.93 <none> 80/TCP 7d8h
mynginx-nodeport NodePort 10.109.68.247 <none> 80:31080/TCP 7d8h
sathish-blog-prod-mariadb ClusterIP 10.106.76.141 <none> 3306/TCP 3m21s
sathish-blog-prod-wordpress LoadBalancer 10.111.81.67 <pending> 80:30594/TCP,443:31054/TCP 3m21s
To accomplish what I want, i need to change the service type to NodePort, keeping other things intact. This is made possible by template file in Helm Chart. We should be able to "Pull" WordPress helm chart from the repository, make changes to the template file and deploy WordPress as NodePort service.
Before proceeding further, let's delete the deployed WordPress instance.
root@sathish-vm2:/home/sathish# helm delete sathish-blog-prod
release "sathish-blog-prod" uninstalled
Pulling WordPress Helm charts
# Pulling WordPress chart locally and extracting
root@sathish-vm2:/home/sathish# helm pull bitnami/wordpress
root@sathish-vm2:/home/sathish# ls
wordpress-10.6.9.tgz
root@sathish-vm2:/home/sathish# tar xvf wordpress-10.6.9.tgz
..........
root@sathish-vm2:/home/sathish/wordpress# ls
Chart.lock charts Chart.yaml ci README.md templates values.schema.json values.yaml
Here is a brief overview of the contents of local charts directory:
charts.yaml: Metadata about the chart.
values.yaml: File where values are configured for template files.
charts directory: This directory contain dependencies (other charts) needed by this chart.
templates: Templates are stored here.
The various values for WordPress are described here.
I am changing the ServiceType to NodePort and adding http/https ports.
service:
type: NodePort
## HTTP Port
##
port: 80
## HTTPS Port
##
httpsPort: 443
## HTTPS Target Port
## defaults to https unless overridden to the specified port.
## if you want the target port to be "http" or "80" you can specify that here.
##
httpsTargetPort: https
## Node Ports to expose
## nodePorts:
## http: <to set explicitly, choose port between 30000-32767>
## https: <to set explicitly, choose port between 30000-32767>
##
nodePorts:
http: "31080"
https: "31443"
Now, let's install WordPress from this chart
root@sathish-vm2:/home/sathish# helm install sathish-blog-prod ./wordpress
NAME: sathish-blog-prod
LAST DEPLOYED: Sun Feb 28 13:06:19 2021
..................
NAMESPACE: default
STATUS: deployed
..........................................
root@sathish-vm2:/home/sathish# kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 136d
my-webservice NodePort 10.103.164.119 <none> 80:30007/TCP 72d
sathish-blog-prod-mariadb ClusterIP 10.111.212.47 <none> 3306/TCP 36s
sathish-blog-prod-wordpress NodePort 10.111.35.83 <none> 80:31080/TCP,443:31443/TCP 36s
Helm deployed with NodePort service type as expected.
Note: Values in values.yaml can also be overridden by specifying a custom yaml file
helm install --values=myvalue.yaml <chartname>
If you have 3 different environments i.e Dev,QA, and prod- with dev, QA being run locally, and prod in the cloud. All, I need to do is change ServiceType to "NodePort" for QA, Dev environments and "LoadBalancer" for production/cloud deployment- ofcourse this process itself can be automated with other CI/CD tools like Jenkins.
Release Management with Helm
Helm supports upgrade, rollbacks just like Kubernetes deployment objects.
helm upgrade <chartname>- Will upgrade the chart recording the changes.
helm rollback <chartname> - Rolls back to a previous version.
Helm is a very powerful tool for package management in Kubernetes and has wide acceptance in DevOps community due to its capabilities.
Hope this short intro to Helm was useful, Helm docs are pretty good and could be used as a great reference.
Have a great week ahead and stay safe :)
Comentarios