DEV Community

Rodel Talampas
Rodel Talampas

Posted on

Local Kubernetes Setup

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 minikube run the following
minikube start
Enter fullscreen mode Exit fullscreen mode
  • Make sure to switch to the minikube context
kubectl config <minikube context>
Enter fullscreen mode Exit fullscreen mode
  • Enable inbound or internal ingress access
minikube addons enable ingress
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

With Helm, you just need to run 1

helm install my-app ./my-chart
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode
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"
Enter fullscreen mode Exit fullscreen mode
values.yaml

Contains configurable settings.

replicaCount: 3

image:
  repository: mycompany/my-app
  tag: latest

service:
  type: ClusterIP
  port: 80
Enter fullscreen mode Exit fullscreen mode

Instead of hardcoding values into Kubernetes YAML, templates reference them:

image:
  repository: {{ .Values.image.repository }}
  tag: {{ .Values.image.tag }}
Enter fullscreen mode Exit fullscreen mode
Templates

Helm uses the Go template engine.

Example Deployment:

spec:
  replicas: {{ .Values.replicaCount }}

containers:
- image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
Enter fullscreen mode Exit fullscreen mode

When you install the chart:

helm install myapp . \
  --set replicaCount=5 \
  --set image.tag=v2
Enter fullscreen mode Exit fullscreen mode

Helm generates:

replicas: 5

image:
  mycompany/my-app:v2
Enter fullscreen mode Exit fullscreen mode

Managing Helm Charts

Install:

helm install my-app .
Enter fullscreen mode Exit fullscreen mode

Upgrade:

helm upgrade my-app .
Enter fullscreen mode Exit fullscreen mode

Rollback:

helm rollback my-app <revision>
Enter fullscreen mode Exit fullscreen mode

Uninstall:

helm uninstall my-app
Enter fullscreen mode Exit fullscreen mode

Top comments (0)