Creating Helm Chart Containing Wordpress and Mysql

Creating Helm Chart Containing Wordpress and Mysql


No alt text provided for this image

Our use case:-

 i) Create a Helm chart containing WordPress and MySQL environment

ii) Publish it on artifacthub.io (This is the official space where helm charts are uploaded.)

As We Know using K8s for managing the container is so dynamic as soon it down deployment again launch it within second . Suppose our Environment contain Two pod one containing the wordpress and other containing Mysql database where we use secret for the password management for security Purpose and lastly we have to Expose our Wordpress pod to the public world but we cannot Expose our Mysql pod.

Now Imagine we Have to Configure the Environment Again and again whenever we required this so Sometime it is annoying although my use case is simple but Suppose it is big environment so again and again recreate this environment is length .

So To Make it simple we use Helm where we Put all this yaml file in one package and by installing this package again and again is simple.

Helm is a tool that streamlines installing and managing Kubernetes applications. Think of it like Apt/Yum/Homebrew for K8S. ... 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.

Step 1: Creating a Helm chart containing wordpress and mysql environment

First we have to create all the yml file

-> Creating pod mysql

apiVersion: apps/v1
kind: Deployment

metadata:
  name: "deploy2"
  labels:
     select: dbdeploy


spec:
   replicas: 1
   selector:
      matchExpressions:
         - { key: prod, operator: In, values: [ frontend ] }
 
   template:

        metadata:
          name: prod
          labels:
             region: in
             prod: frontend
        spec: 
          containers:
          - name: mydb
            image: mysql:5.7
            env:
            - name: MYSQL_ROOT_PASSWORD
              valueFrom:
                  secretKeyRef:
                     name: mysecret
                     key: root_password
            - name: MYSQL_PASSWORD
              valueFrom:
                  secretKeyRef:
                    name: mysecret
                    key:  user_password
            - name: MYSQL_PASSWORD
              value: redhat
            - name: MYSQL_DATABASE
              value: wpdp
            - name: MYSQL_USER
              value: vinayak        

-> Creating Pod Wordpress

apiVersion: apps/v1
kind: Deployment

metadata:
  name: "deploy1"
  labels:
     select: wordpressdeploy

spec:
   replicas: 3
   selector:
      matchExpressions:
         - { key: prod, operator: In, values: [ db ] }
 
   template:

        metadata:
          name: prod
          labels:
             region: in
             prod: db
        spec: 
          containers:
          - name: "w1"
            image: "wordpress:5.1.1-php7.3-apache"        

-> Creating Secret

apiVersion: v1
kind: Secret
metadata:
   name : mysecret

data: 
  root_password: cmVkaGF0
  user_password: dWJ1bnR1        

-> Exposing pod wordpress

apiVersion: v1
kind: Service
metadata:
    name: wordpressservice
    labels:
        resource: service1

spec:
   type: NodePort
   selector:
        prod: db
   ports:
      - targetPort: 80
        port: 8080
        nodePort: 30005        

Now we have to create helm Package For that We have to create Chart.yaml file Here we have to Mention the Version of the Package .

No alt text provided for this image

Now we can See our Environment Is creating by Helm and we Can use it again and again

No alt text provided for this image

Now we can Login using Master Ip using port 30005

No alt text provided for this image

Step 2 :- Uploading Helm Chart in the artifacthub.io (This is official site of the Helm chart )

There are several step to upload the chart in the artifacthub.io

Step 1) :- Create Directory and create package of chart2

No alt text provided for this image

Here we create directory charts/ and create package and copy in this folder

Step 2) :- Now we have to create index.yaml file it is necessary file as artifact.io check this file while uploading

$ helm repo index charts/        

This is command to create the index.yaml file after running this command you can see there is index.yaml file inside the charts/

No alt text provided for this image

Step 3) :- Now we have to upload the charts/ and index.yaml file in this github repository as here we use github repository ti host our helm chart

No alt text provided for this image

Step 4) :- Now we need link of github repository which we need while uploading it in artifact.io

We get this link in setting of github repository in github page section

No alt text provided for this image

Step 5) :- Now we Have to login in our account of artifact.io

Click on add repository.

Select the kind as Helm charts, provide a name to the repository and enter the URL to the charts (which we get from the github repository) and click on add . If everything is good then you package publish succesfully.

Step 6) :- First we have to , run following command to check if we have any helm repositories added.

helm repo list        

Note:- For installing any helm chart, we first required to add the repository in which that chart is present

helm repo  add <name of package> <url>

helm repo add wordpress-mysql  https://vinayak04u.github.io/helm-chart/        
No alt text provided for this image

Now we can install the Package

To view or add a comment, sign in

More articles by VINAYAK KUMAR

Others also viewed

Explore content categories