Deploy using Helm charts

Category : Kubernetes | Sub Category : Kubernetes With Java | By Prasad Bonam Last updated: 2023-11-21 13:34:39 Viewed : 232


Deploying using Helm charts involves creating a Helm chart, which is a package of pre-configured Kubernetes resources, and then installing the chart onto a Kubernetes cluster. Below is a step-by-step guide to deploying a simple NGINX application using Helm charts:

1. Install Helm:

If you have not already, you need to install Helm on your local machine. Follow the instructions on the official Helm installation guide for your operating system.

2. Create a Helm Chart:

Create a new directory for your Helm chart. In this example, let`s call it my-nginx-chart.

bash
mkdir my-nginx-chart cd my-nginx-chart

Inside the directory, create a Chart.yaml file with the following content:

yaml
apiVersion: v2 name: my-nginx-chart description: A Helm chart for deploying NGINX version: 0.1.0

3. Create values.yaml:

Create a values.yaml file with default configuration values:

yaml
# values.yaml replicaCount: 3 image: repository: nginx tag: latest pullPolicy: IfNotPresent service: type: LoadBalancer port: 80

4. Create Templates:

Create a templates/ directory and add two files: deployment.yaml and service.yaml.

deployment.yaml:

yaml
# templates/deployment.yaml apiVersion: apps/v1 kind: Deployment metadata: name: {{ include "my-nginx-chart.fullname" . }} spec: replicas: {{ .Values.replicaCount }} selector: matchLabels: app: {{ include "my-nginx-chart.name" . }} release: {{ .Release.Name }} template: metadata: labels: app: {{ include "my-nginx-chart.name" . }} release: {{ .Release.Name }} spec: containers: - name: nginx image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" imagePullPolicy: {{ .Values.image.pullPolicy }} ports: - containerPort: 80

service.yaml:

yaml
# templates/service.yaml apiVersion: v1 kind: Service metadata: name: {{ include "my-nginx-chart.fullname" . }} spec: selector: app: {{ include "my-nginx-chart.name" . }} release: {{ .Release.Name }} ports: - protocol: TCP port: {{ .Values.service.port }} targetPort: 80 type: {{ .Values.service.type }}

5. Install the Helm Chart:

Now, you can install the Helm chart onto your Kubernetes cluster:

bash
helm install my-nginx-release ./my-nginx-chart

Replace my-nginx-release with the desired release name.

6. Verify the Deployment:

Check the status of the deployment:

bash
kubectl get deployments

Check the status of the service:

bash
kubectl get services

If you are using Minikube, you can access the NGINX service using:

bash
minikube service my-nginx-release

For cloud providers, wait for the external IP to be assigned to the service and access the application using that IP.

7. Upgrade the Helm Chart:

To make changes to your deployment, update the values.yaml file or the template files, and then upgrade the Helm chart:

bash
helm upgrade my-nginx-release ./my-nginx-chart

8. Cleanup:

To delete the deployed Helm release and associated resources:

bash
helm uninstall my-nginx-release

This removes the NGINX deployment and service from the cluster.

Helm charts provide a convenient way to package, deploy, and manage applications on Kubernetes, making it easier to share and reproduce complex application configurations.

Search
Related Articles

Leave a Comment: