Deploying applications to Kubernetes can be a complex process, as even the simplest applications contain multiple containers or Pods. Kubernetes deployments are becoming even more complex, with more and more applications shifting to decoupled architectures using microservices and event-driven design patterns.
Helm is a good solution to bridge this deployment complexity and package Kubernetes applications with all dependencies, including other containers/Pods, services, secrets, ConfigMaps, etc. Moreover, helm provides users a simplified way of deploying applications across a Kubernetes cluster. In this post, we will see how to deploy a LAMP stack in a K8s as a Helm Chart.
Helm acts as a package manager for Kubernetes. Similar to traditional package managers like apt, yum, packman, and widget, which allow users to simply search, install, upgrade, and delete software on their targeted operating systems, helm aims to provide the same functionality in a Kubernetes environment.
Helm utilizes Helm Charts to package Kubernetes applications. These charts can then be versioned and published in a repository like Artifacthub.io and utilized to install applications in any Kubernetes cluster. Since helm charts are versioned, updating applications is as
Before moving into using Helm charts, let’s see how to normally deploy a LAMP stack in a Kubernetes cluster. A LAMP stack consists of Apache, MySQL, and PHP. Thus, users will have to manage at least two deployments as one for a container consisting of a database (MySQL) and the other for the webserver with PHP (Apache). Before that, you will need to set up Secrets, storage volumes, ConfigMaps, etc., and then create a deployment file and deploy the application. Following is an example deployment file for MySQL with a secret for the root password, persistent volume, and service.
apiVersion: v1 kind: Service metadata: name: mysql spec: ports: - port: 3306 selector: app: mysql clusterIP: None --- apiVersion: apps/v1 kind: Deployment metadata: name: mysql spec: selector: matchLabels: app: mysql strategy: type: Recreate template: metadata: labels: app: mysql spec: containers: - image: mysql:8.0.28 name: mysql env: - name: MYSQL_DATABASE value: web_db - name: MYSQL_ROOT_PASSWORD valueFrom: secretKeyRef: name: mysql-pass key: password.txt ports: - containerPort: 3306 name: mysql volumeMounts: - name: mysql-persistent-storage mountPath: /var/lib/mysql volumes: - name: mysql-persistent-storage persistentVolumeClaim: claimName: mysql-pv-claim
You will need to create another deployment manifest for Apache and PHP. When it’s time to update the deployment, you will need to modify the files and redeploy them again. If you have deployed them in multiple clusters, you will need to change the deployment manifest in each cluster and redeploy. This approach has its own risks since an error in a modification can completely break an application. There is also a high chance of creating an incorrect configuration if manifests are constantly changed and clusters are managed by multiple parties.
Since LAMP consists of common applications, you can simply search for the appropriate charts within a
Simply run the search command with the name of the repository and chart to search via the CLI. Here we have searched for an apache chart.
helm search hub apache
Once you find the appropriate charts, the next step is to install them. In this example, we will use
helm repo add bitnami https://charts.bitnami.com/bitnami helm install k8s-apache --set imagePullPolicy=Always bitnami/apache helm install k8s-mysql --set auth.rootPassword=testpassword123,auth.database=lamp_database bitnami/mysql
The above commands will install apache and MySQL within our Kubernetes cluster. We have provided the imagePullPolicy parameter for the Apache chart to always download the container image and set the root password and the database for MySQL. Even though there is a misconception that charts cannot be customized, it is not true. However, the values that can be modified will depend on the configuration of the chart. These
We can use the get all command to verify if the appropriate resources are created in our cluster.
kubectl get all
If you need to uninstall the charts, simply run the helm uninstall command to remove these applications from the cluster.
helm uninstall k8s-apache k8s-mysql
In the previous section, we covered how to create a LAMP stack by installing individual helm charts for the different components of the stack without creating any manifest files or configurations. We can further simplify this process by looking for a chart that consists of a complete LAMP stack.
helm search hub lamp
helm repo add lamp https://lead4good.github.io/lamp-helm-repository helm install k8s-lamp lamp/lamp
kubectl get all
That’s it, and you have successfully created a LAMP stack in Kubernetes using a single Helm Chart.
Helm is a powerful tool to manage applications within a Kubernetes cluster, simplifying deployments and updates. However, there is one pain point in using helm. The users will be responsible for creating and maintaining these helm charts, which can be a complex task, especially when it comes to custom applications. A Tool like Cloudplex aims to solve this problem by offering features like automated Helm chart generation and managed deployments for cloud-native containerized applications, all within a low code solution. So why not give
Also published here.