Kubernetes Getting Started
Let’s setup Kubectl and Minikube and use Minikube to setup a one node cluster.
Prerequisite
Download and install VirtualBox. see Download page https://www.virtualbox.org/wiki/Linux_Downloads
Install Kubectl
The Kubernetes command-line tool, kubectl, allows you to run commands against Kubernetes clusters. Installation instruction is in https://kubernetes.io/docs/tasks/tools/install-kubectl/#install-kubectl-on-linux.
1 | curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl |
To check kubectl installation
1 | kubectl version |
The config file is in the $HOME/.kube directory. This file defines clusters, context and users. You can view the file using command kubectl config view
.
If the configuration file is not working as expected, use rm -rf ~/.kube
command to remove the existing configuration and cache.
Useful links for kubectl:
Install Minikube
minikube is a tool that runs a single-node Kubernetes cluster in a virtual machine on your personal computer. see Install Instructions https://kubernetes.io/docs/tasks/tools/install-minikube/
Download and install minikube
1 | curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 \ |
You can check minikube version using minikube version
command.
Note hat Minikube can only set up a one node cluster.
Set Up a Cluster with Minikube
A brief guide to start use, and delete Minikube locally. See https://kubernetes.io/docs/tasks/tools/install-minikube/
1 - Start Minikube and create a cluster. You can optionally specify cpu and memory.
1 | $ minikube start --memory=10000 --cpus=4 |
You can use minikube status
to check its status. also use kubectl get pods --all-namespaces
command to ensure all pods are running without error.
Now minikube will start a Virtual Machine. The cluster runs on that Virtual Machine. If you open VirtualBox Manager, you will see a virtual machine named “minikube”.
check cluster info using kubectl cluster-info
command
1 | $ kubectl cluster-info |
To view the nodes, use kubectl get nodes
command
2 - create a deployment
1 | kubectl run hello-minikube --image=k8s.gcr.io/echoserver:1.10 --port=8080 |
You can use kubectl get deployments
to list deployments and kubectl describe deployments/hello-minikube
to get details of a particular deployment.
3 - Expose deployment as a service
1 | kubectl expose deployment hello-minikube --type=NodePort |
4 - If you check the pods, it should return a pod
1 | $ kubectl get pods |
You can use kubectl scale deployments/hello-minikube --replicas=3
to scale the deployment to 3 replicas
5 - Get the url of the exposed service
1 | $ minikube service hello-minikube --url |
Note that the port number is randomly assigned
6 - View the web page using the URL
1 | $ curl http://192.168.99.101:31777 |
7 - Open dashboard
Dashboard is a web-based Kubernetes user interface. You can use Dashboard to deploy containerized applications to a Kubernetes cluster, troubleshoot your containerized application, and manage the cluster resources.
run this command to open dashboard in the browser
1 | $ minikube dashboard |
Dashboard is a great tool to monitor minikube cluster.
8 - Delete the service
1 | $ kubectl delete services hello-minikube |
9 - Delete the deployment
1 | $ kubectl delete deployment hello-minikube |
10 - Stop the local Minikube cluster
1 | $ minikube stop |
10 - Delete minikube cluster
If you don’t need the cluster any more, delete the cluster.
1 | $ minikube delete |
More on Minikube
By Default. Minikube creates node on Virtualbox VM. the default settings is CPUs=2, Memory=2000MB, Disk=20000MB. You can override the default settings:
1 | minikube start --memory=6000 --cpus=4 --disk-size=10000 |
For more options, see start command
Other minikube commands
1 | # check minikube status |
You can configure docker CLI to use minikube’s Docker Daemon.
1 | $ minikube docker-env |
For more information on Minikube, see [Minikube documentation](https://minikube.sigs.k8s.io/docs/
Other Ways to setup a Cluster
Minikube creates a single node cluster. If you want to create a multi-node cluster, checkout
kubeadm.
A more convenient way to run a multi-node cluster is kind. With kindl you can easily setup local Kubernetes clusters using Docker container
There is also online option to play with Kubernetes. Katacoda Playground sets up a two node cluster cluster for you to play with. Another online kubernetes playgound is play-with-k8s
Resources
These are the resources for learning Kubernetes