This guide will walk you through the steps to setting up an
environment to run Kubernetes (K8S) on your laptop or workstation.
You'll need to install Docker if you haven't already and
Kubernetes client (kubectl).
Update: For guide using Minikube, a common local K8S environment,
checkout Run a
Minikube Local Docker Registry and Dashboard using Helm
Kubectl:
Follow the instructions at Installing
and Setting up kubectl to install kubectl. kubectl is the general
purpose CLI client for inspecting and manipulating a kubernetes cluster.
Run Kubernetes using Docker
Once you have Docker Toolbox installed, you can leverage Docker to
run Kubernetes with hyperkube. First, setup the Kubernetes version environment
variable.
Now run the Kubernetes Hyperkube image. This image will run
additional Kubernetes images used to orchestrate your
cluster. I've added --restart=always so that Kubernetes will be
relaunched on reboots, or if it dies. You may tweak these starting
parameters at some point(i.e. --cluster-dns), but they ought to provide
working defaults for now.
Start a private local registry that Docker always restarts if the container dies.
docker run -d -p 5000:5000 --restart=always --name registry registry:2
Build an image and tag it.
docker build -t hello-node .
docker tag hello-node localhost:5000/hello-node
Push the image to your local registry.
docker push localhost:5000/hello-node
Now run a deployment in Kubernetes using the image located on your
local registry.
kubectl run hello-node --image=localhost:5000/hello-node--port=8888
Conclusion
You should now have a deployment of your image, in my case hello-node, running using your
private local registry, Kubernetes and Docker. You can verify by
running
kubectl get deployments
You may also connect to your pod via port forwarding to verify
connectivity. For example, I forward traffic from 8090 on
my localhost to port 8080 on a jenkins pod. Now when I point
my browser to localhost:8090, I talk to the jenkins web service.