Kubernetes Deployment with Helm
This post is a quick guide to show how to deploy a containerized application in k8s using helm.
Full code here
Create Sample App
Creating a sample flask application that runs on top of a python base image.
mkdir webapp
cd webapp
python -m venv .env
pip install Flask
pip freeze > requirements.txt
Copy the minimal application from https://flask.palletsprojects.com/en/1.1.x/quickstart/ to app.py
Docker Setup
Create the dockerfile
FROM python:3.8-slim-buster
WORKDIR /app
COPY webapp/requirements.txt requirements.txt
RUN pip3 install -r requirements.txt
COPY webapp/app.py app.py
CMD [ "python3", "-m" , "flask", "run", "--host=0.0.0.0", "--port=80"]
Build the image
docker build -t helmsample:v1 .
Run the container
docker run -d -p 8080:80 helmsample:v1
application should be running at http://localhost:8080
Stop the container
docker stop dockerId
Setting up Helm
helm create deploy
Update few values
image:
- repository: nginx
+ repository: helmsample
pullPolicy: IfNotPresent
# Overrides the image tag whose default is the chart appVersion.
- tag: ""
+ tag: "v1"
ingress:
- enabled: false
+ enabled: true
className: ""
- annotations: {}
- # kubernetes.io/ingress.class: nginx
- # kubernetes.io/tls-acme: "true"
+ annotations:
+ kubernetes.io/ingress.class: nginx
+ kubernetes.io/tls-acme: "true"
hosts:
- host: chart-example.local
paths:
Enable Ingress Controller
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v0.41.2/deploy/static/provider/cloud/deploy.yaml
Switch to docker-desktop context
kubectl config use-context docker-desktop
Install helm chart
cd deploy
helm install deploy ./
Fetching localhost with chart-example.local
host header will repond with sample app
curl -v http://localhost -H "Host: chart-example.local"
Update the hosts file and you will see the page in browser as well http://chart-example.local/