To deploy your Docker image (sample-webapi:1.0.0) to an Azure Kubernetes Service (AKS) cluster using Helm, you will need to create several Kubernetes resource files and a Helm chart to organize them. Here are the necessary Kubernetes resource files:
- Deployment: A file defining the Deployment resource that manages the lifecycle of your application's pods.
- Service: A file defining the Service resource that exposes your application within the Kubernetes cluster and optionally externally.
- (Optional) Ingress: A file defining the Ingress resource to expose your application externally using a load balancer or the Azure cloud's ingress controller.
Create a new directory for your Helm chart and follow the directory structure below:
chart/
|- templates/
| |- deployment.yaml
| |- service.yaml
| |- ingress.yaml (optional)
|- Chart.yaml
|- values.yaml
values.yaml
image:
repository: sample-webapi
tag: 1.0.0
pullPolicy: IfNotPresent
service:
type: ClusterIP
port: 80
targetPort: 80
ingress:
enabled: false
annotations: {}
hosts:
- host: chart-example.local
paths: []
resources:
limits:
cpu: "1"
memory: "512Mi"
requests:
cpu: "100m"
memory: "256Mi"
deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "sample-webapi.fullname" . }}
spec:
replicas: {{ .Values.replicaCount }}
selector:
matchLabels:
app.kubernetes.io/name: {{ include "sample-webapi.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
template:
metadata:
labels:
app.kubernetes.io/name: {{ include "sample-webapi.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
spec:
containers:
- name: {{ .Chart.Name }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
ports:
- name: http
containerPort: {{ .Values.service.targetPort }}
protocol: TCP
resources:
{{- toYaml .Values.resources | nindent 12 }}
service.yaml
apiVersion: v1
kind: Service
metadata:
name: {{ include "sample-webapi.fullname" . }}
spec:
type: {{ .Values.service.type }}
ports:
- port: {{ .Values.service.port }}
targetPort: {{ .Values.service.targetPort }}
protocol: TCP
name: http
selector:
app.kubernetes.io/name: {{ include "sample-webapi.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
ingress.yaml (optional)
{{- if .Values.ingress.enabled }}
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: {{ include "sample-webapi.fullname" . }}
annotations:
{{- toYaml .Values.ingress.annotations | nindent 8 }}
spec:
rules:
{{- range .Values.ingress.hosts }}
- host: {{ .host }}
http:
paths:
{{- range .paths }}
- path: {{ .path }}
pathType: Prefix
backend:
service:
name: {{ include "sample-webapi.fullname" . }}
port:
name: http
{{- end }}
{{- end }}
{{- end }}
Chart.yaml
apiVersion: v2
name: sample-webapi
description: A Helm chart for sample-webapi
type: application
version: 0.1.0
appVersion: 1.0.0
To install the Helm chart, run:
helm install my-sample-webapi ./chart
Remember to replace the chart-example.local hostname in the values.yaml file with the hostname you want to use. If you want to use an Ingress resource, ensure that an Ingress controller, such as nginx or traefik, is installed in your AKS cluster.