Helm tutorial 2
I have a Go project that built as a Docker container, let me use a Helm chart to deploy it into the current Kubernetes namespace:
Step 1: Create a Helm Chart
Run the following command to generate a Helm chart structure:
helm create my-go-app
This will create a directory named my-go-app
with the default Helm chart structure.
Step 2: Modify the values.yaml
File
Navigate to the my-go-app
directory and edit the values.yaml
file to define your application’s configuration:
# values.yaml
replicaCount: 1
image:
repository: my-docker-repo/my-go-app # Replace with your Docker image repository
tag: latest # Replace with your desired image tag
pullPolicy: IfNotPresent
service:
type: ClusterIP
port: 80
targetPort: 8080
ingress:
enabled: false # Set to true if you want to use Ingress
resources: {} # Define resource limits if needed
autoscaling:
enabled: false
nodeSelector: {}
tolerations: []
affinity: {}
Step 3: Update the deployment.yaml
Template
Modify templates/deployment.yaml
to use your Go application’s Docker image:
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ .Release.Name }}
spec:
replicas: {{ .Values.replicaCount }}
selector:
matchLabels:
app: {{ .Release.Name }}
template:
metadata:
labels:
app: {{ .Release.Name }}
spec:
containers:
- name: my-go-app
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
ports:
- containerPort: {{ .Values.service.targetPort }}
env: # Add any environment variables if needed
- name: ENV_VAR_NAME
value: "your-value"
Step 4: Update the service.yaml
Template
Modify templates/service.yaml
to expose your Go application:
apiVersion: v1
kind: Service
metadata:
name: {{ .Release.Name }}
spec:
type: {{ .Values.service.type }}
selector:
app: {{ .Release.Name }}
ports:
- protocol: TCP
port: {{ .Values.service.port }}
targetPort: {{ .Values.service.targetPort }}
Step 5: Deploy the Helm Chart
Set Your Namespace (If Not Already Set)
Ensure you are deploying to the correct namespace:
kubectl config set-context --current --namespace=<your-namespace>
Install the Helm Chart
Run the following command to deploy your Go application:
helm install my-go-app ./my-go-app
Verify Deployment
Check the status of the pods:
kubectl get pods
Check if the service is running:
kubectl get svc
Step 6: Upgrade or Uninstall the Helm Release
Upgrade the Deployment
If you make changes to the chart, upgrade it:
helm upgrade my-go-app ./my-go-app
Uninstall the Deployment
To remove the application:
helm uninstall my-go-app
Next Steps
- Add Ingress support if needed.
- Enable autoscaling if required.
- Configure Persistent Volumes for data storage.
Would you like help setting up Ingress or autoscaling? 🚀