Simple chart with helm
Install
brew install helm
Create simple app
Create app.py
files:
from fastapi import FastAPI
app = FastAPI()
@app.get("/")
async def root():
return {"message": "Hello World"}
requirements.txt
:
fastapi==0.62.0
and Dockerfile
:
FROM python:3.8.6
EXPOSE 8008
ADD requirements.txt .
RUN pip install -r requirements.txt
ADD app.py .
CMD uvicorn app:app --reload --port 8080 --host 0.0.0.0
Run docker:
docker build -t barteks/simple-helm .
Change barteks
into your Docker Hub username.
Then you can check your docker with:
docker run -p 8080:8080 --rm -it barteks/simple-helm
Now push the docker to Docker Hub
docker push barteks/simple-helm
Run it in Kubernetes
Let’s test it in minkube. Run minikube:
minikube start
kubectl create deployment simple-helm --image=barteks/simple-helm
kubectl expose deployment simple-helm --type=LoadBalancer --port=8080
minikube service simple-helm
With yaml
Create deployment.yaml
with
apiVersion: apps/v1
kind: Deployment
metadata:
name: simple-helm
spec:
replicas: 1
selector:
matchLabels:
app.kubernetes.io/name: simple-helm
template:
metadata:
name: simple-helm
labels:
app.kubernetes.io/name: simple-helm
spec:
containers:
- image: barteks/simple-helm
name: simple-helm
ports:
- name: http
containerPort: 8080
protocol: TCP
---
apiVersion: v1
kind: Service
metadata:
name: simple-helm
spec:
selector:
app.kubernetes.io/name: simple-helm
ports:
- protocol: TCP
port: 8080
Then
kubectl apply -f deployment.yaml
Clean
kubectl delete service simple-helm
kubectl delete deployment simple-helm
Helm
helm create simple-helm-chart
image
repository: barteks/simple-helm
pullPolicy: IfNotPresent
tag: latest
service:
name: simple-helm
type: LoadBalancer
externalPort: 8080
internalPort: 8008
port: 8080
Also in templates/deployment.yaml
correct the port of the container:
containerPort: 8080
You can check your helm files with (run it from simple-helm-chart
directory)
helm lint
Now you are ready to package (run it from root directory):
helm package simple-helm-chart
You should have simple-helm-chart-0.1.0.tgz
file.
Run helm in Kubernetes
In k8s cluster run:
helm install simple-helm simple-helm-chart-0.1.0.tgz
Then, in minikube:
minikube service simple-helm-simple-helm-chart
Get status:
helm status simple-helm
Uninstall
helm uninstall simple-helm
Updated: 2020-12-13