Minikube will allow you to setup local kubernetes cluster on Windows, macOS or Linux machine very easily. You can follow on how to setup minikube in your local machine.
Once you have installed minikube, start your cluster.
$minikube start
😄 minikube v1.10.1 on Debian Parrot
✨ Using the virtualbox driver based on existing profile
👍 Starting control plane node minikube in cluster minikube
🔄 Restarting existing virtualbox VM for "minikube" ...
🐳 Preparing Kubernetes v1.18.2 on Docker 19.03.8 ...
🌟 Enabled addons: dashboard, default-storageclass, storage-provisioner
🏄 Done! kubectl is now configured to use "minikube"
2. Getting Kubernetes CLI
To interact with your new kubernetes cluster you will need kubectl. Download the latest binary of kubectl for Linux with the commands below.
#Downloading the kubectl binary
$curl -LO https://storage.googleapis.com/kubernetes-release/release/`curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt`/bin/linux/amd64/kubectl
#Making the binary executeable
$chmod +x ./kubectl
#Moving kubectl binary to $PATH
$sudo mv ./kubectl /usr/bin/kubectl
Once you finished setting up kubectl,check it's version. Try using it to check your new local cluster status.
$kubectl version --client
Client Version: version.Info{Major:"1", Minor:"18", GitVersion:"v1.18.3", GitCommit:"2e7996e3e2712684bc73f0dec0200d64eec7fe40", GitTreeState:"clean", BuildDate:"2020-05-20T12:52:00Z", GoVersion:"go1.13.9", Compiler:"gc", Platform:"linux/amd64"}
$kubectl get nodes
NAME STATUS ROLES AGE VERSION
minikube Ready master 3d3h v1.18.2
$kubectl get po -A
NAMESPACE NAME READY STATUS RESTARTS AGE
kube-system coredns-66bff467f8-k96mv 1/1 Running 6 3d3h
kube-system coredns-66bff467f8-txkn2 1/1 Running 6 3d3h
kube-system etcd-minikube 1/1 Running 4 3d3h
kube-system kube-apiserver-minikube 1/1 Running 4 3d3h
kube-system kube-controller-manager-minikube 1/1 Running 4 3d3h
kube-system kube-proxy-rzzlq 1/1 Running 4 3d3h
kube-system kube-scheduler-minikube 1/1 Running 4 3d3h
kube-system storage-provisioner 1/1 Running 6 3d3h
kubernetes-dashboard dashboard-metrics-scraper-84bfdf55ff-sjs97 1/1 Running 4 2d6h
kubernetes-dashboard kubernetes-dashboard-696dbcc666-lvzjl 1/1 Running 6 2d6h
3. Create & Run your Service (nginx)
Let's deploy simple a nginx web-server on our local kubernetes cluster.
#Running a nginx image on our cluster
$kubectl create deployment nginx-server --image=nginx
deployment.apps/nginx-server created
#See the status of running pod
$kubectl get pods
NAME READY STATUS RESTARTS AGE
nginx-server-69886f95bc-l5zf2 1/1 Running 0 103s
4. Expose Nginx Pod with NodePort
In order to access the service in our newly created nginx pod, we need to expose port 80 using NodePort service like following.
Similarly, if you want to expose your kubernetes dashboard,
$kubectl proxy --address='0.0.0.0' --disable-filter=true
W0529 01:25:13.905234 23151 proxy.go:167] Request filter disabled, your proxy is vulnerable to XSRF attacks, please be cautious
Starting to serve on [::]:8001