Category : Kubernetes | Sub Category : Kubernetes With Java | By Prasad Bonam Last updated: 2023-11-21 13:34:39 Viewed : 625
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:
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.
Create a new directory for your Helm chart. In this example, let`s call it my-nginx-chart
.
bashmkdir my-nginx-chart
cd my-nginx-chart
Inside the directory, create a Chart.yaml
file with the following content:
yamlapiVersion: v2
name: my-nginx-chart
description: A Helm chart for deploying NGINX
version: 0.1.0
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
Create a templates/
directory and add two files: deployment.yaml
and service.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
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 }}
Now, you can install the Helm chart onto your Kubernetes cluster:
bashhelm install my-nginx-release ./my-nginx-chart
Replace my-nginx-release
with the desired release name.
Check the status of the deployment:
bashkubectl get deployments
Check the status of the service:
bashkubectl get services
If you are using Minikube, you can access the NGINX service using:
bashminikube 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.
To make changes to your deployment, update the values.yaml
file or the template files, and then upgrade the Helm chart:
bashhelm upgrade my-nginx-release ./my-nginx-chart
To delete the deployed Helm release and associated resources:
bashhelm 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.