Show List

Creating a simple Helm Chart

A Helm chart is a package that contains all the resources needed to run an application on a Kubernetes cluster. Helm charts are stored in a repository, which is a collection of charts. In this section, we will create a simple Helm chart for a basic web application.

Here are the steps to create a simple Helm chart:

  1. Create a new directory for your chart. For example:
shell
Copy code
$ mkdir mychart $ cd mychart
  1. Initialize the chart by running the following command:
lua
Copy code
$ helm create .

This command generates the basic directory structure for a Helm chart and creates a file named Chart.yaml that contains the chart's metadata.

  1. Next, we need to specify the resources that the chart needs to run our application. To do this, we will create a YAML file for each resource we want to deploy. For example, let's create a file called templates/deployment.yaml for a Kubernetes Deployment resource:
yaml
Copy code
apiVersion: apps/v1 kind: Deployment metadata: name: {{ .Release.Name }}-deployment labels: app: {{ .Release.Name }} spec: replicas: 1 selector: matchLabels: app: {{ .Release.Name }} template: metadata: labels: app: {{ .Release.Name }} spec: containers: - name: {{ .Release.Name }} image: nginx:alpine ports: - containerPort: 80

This YAML file specifies a Deployment resource that will run a single replica of an nginx container on port 80.

  1. Next, let's create a Service resource that will expose the deployment. Create a file called templates/service.yaml:
yaml
Copy code
apiVersion: v1 kind: Service metadata: name: {{ .Release.Name }}-service labels: app: {{ .Release.Name }} spec: selector: app: {{ .Release.Name }} ports: - name: http port: 80 targetPort: 80 type: ClusterIP

This YAML file creates a Service resource that will expose the Deployment on port 80 with a ClusterIP type, which makes the service only accessible within the cluster.

  1. Finally, we need to tell Helm to use these templates. Open the Chart.yaml file and add the following to the templates section:
yaml
Copy code
templates: - deployment.yaml - service.yaml
  1. That's it! You have created a simple Helm chart that can be used to deploy a basic web application to a Kubernetes cluster. To test the chart, run the following command:
css
Copy code
$ helm install --name myrelease .

This command installs the chart in your cluster with the name myrelease.

You can use the helm list command to see the releases installed in your cluster and the helm delete command to delete a release.


    Leave a Comment


  • captcha text