How to: Run Kubernetes Locally


Why run Kubernetes locally?
If you want to run your app in a dev environment that will emulate what production will look like this is a way to do it locally from your workstation. There are kubernetes mechanisms like Liveness, Readiness and Startup Probes that you may want to app to leverage and these can be tested in your kubernetes local cluster.

In this example I’ll use kind but there are other options like minikube.

Create a new cluster working from the terminal once all the requisites have been met:

kind create cluster --name new-test-cluster

Once completed confirm that it exists with the following

kind get clusters

To communicate with the cluster and see everything is running run:

kubectl cluster-info

Note that kind has already setup a context to talk to the kind kubernetes cluster just is visible with

kubectl config get-contexts
kubectl  get nodes # Displays the node that kind has setup
kubectl get all -A # Shows everything kind setup to get the cluster kubernetes running 

Creating a pod and how is if different to a docker container:
Where in Docker containers will be presented a unique network namespace and file system to each container. In Kubernetes, a pod is a collection of one or more of these containers that are deployed together on the same host. All containers running the same pod will share a network namespace, and optionally file system volumes. A pod is the smallest deployable work load in kubernetes.

Deploying a pod using a pod manifest:

create a yaml with the following

apiVersion: v1
kind: Pod
metadata:
     name: new-app-pod
spec: 
  containers:
  - name: new-app-container01
    image: lander2k2/building-apps:0.1

Spin up the pod with the following kubectl command.

kubectl apply -f NAMEOFFILE.yaml
kubectl get pods
#To remove it
kubectl delete pod PODNAME


You May Also Like

About the Author: Phil

Leave a Reply

Your email address will not be published. Required fields are marked *