I started learning Kubernetes or Kube a few years ago but never really written a documentation on how I started. I am not an expert, if you are going to ask, but I know my ways.
In this short document, I used helm and minikube as my tools. If you are using Windows as your OS (or wants a Linux GUI instead), the Docker Desktop alone is your friend. Just enable Kubernetes and it will download everything you need as a start. But if you are a linux terminal fan like me, then this is a guide.
Let's start.
Prerequisites
- docker client : There are many ways to install the docker client. I'd like to install it from apt directory (ubuntu fan here). This guide can help.
- kube client (kubectl) : Similarly, you can install kubectl in different ways. I install it using homebrew.
- helm : I was introduced to helm version 2 but recently changed to helm version 3. And its a big change. I would advise to use helm 3.
- minikube : This is your local kubernetes cluster.
Basic Docker Commands
- build :
docker build -t myapptag -f myapp/Dockerfile . - run :
docker run -p <container port>:<host port> myapptag
Server Running Locally
- To start the local server
minikuberun the following
minikube start
- Make sure to switch to the minikube context
kubectl config <minikube context>
- Enable inbound or internal ingress access
minikube addons enable ingress
Helm Chart
A Helm Chart is a package for deploying applications to a Kubernetes cluster.
If Docker images are like compiled applications, then Helm Charts are like installers that know how to deploy and configure those applications on Kubernetes.
Without Helm, you need to use kubectl commands multiple times
kubectl apply -f deployment.yaml
kubectl apply -f service.yaml
kubectl apply -f ingress.yaml
kubectl apply -f configmap.yaml
kubectl apply -f secret.yaml
kubectl apply -f hpa.yaml
With Helm, you just need to run 1
helm install my-app ./my-chart
What is inside a Helm Chart?
A typical chart looks like this:
my-chart/
├── Chart.yaml # Chart metadata
├── values.yaml # Default configuration
├── templates/
│ ├── deployment.yaml
│ ├── service.yaml
│ ├── ingress.yaml
│ ├── configmap.yaml
│ └── hpa.yaml
└── charts/ # Dependencies
Chart.yaml
Defines information about the package to be deployed
apiVersion: v2
name: my-app
description: My application
version: 1.0.0
appVersion: "2.5.1"
values.yaml
Contains configurable settings.
replicaCount: 3
image:
repository: mycompany/my-app
tag: latest
service:
type: ClusterIP
port: 80
Instead of hardcoding values into Kubernetes YAML, templates reference them:
image:
repository: {{ .Values.image.repository }}
tag: {{ .Values.image.tag }}
Templates
Helm uses the Go template engine.
Example Deployment:
spec:
replicas: {{ .Values.replicaCount }}
containers:
- image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
When you install the chart:
helm install myapp . \
--set replicaCount=5 \
--set image.tag=v2
Helm generates:
replicas: 5
image:
mycompany/my-app:v2
Managing Helm Charts
Install:
helm install my-app .
Upgrade:
helm upgrade my-app .
Rollback:
helm rollback my-app <revision>
Uninstall:
helm uninstall my-app
Top comments (0)