If you are interested in to learn how Kubernetes works, you came to the right place! In this tutorial, I will show you how to quickly setup local Kubernetes environment using
minikube to run
hello-world app in a container.
Lets ensure we have pre-requisites installed before we get started with minikube installation. If you already have below items install, you can skip them and proceed with minikube setup.
Open PowerShell console as an administrator.
Install minikube by executing below command:
choco install minikube
NOTE: It may take a while to install minikube depending on your network speed.
Verify your installation succeeded and it should look like as shown below:
Setting up Hyper-V environment
- Open Hyper-V manager.
- Open Virtual Switch Manager from Action panel on the right hand side.
New virtual network switch-> select
External-> click on
Create Virtual Switch.
- Name your virtual switch to
Minikube Virtual Switch, select correct LAN settings that gives access to internet and click on apply and ok.
NOTE: If you already have
virtual switchcreated before, you may not need to setup virtual switch. This instruction is for newly install hyper-v environment.
PowerShellas an administrator. If you already have it opened then you can ignore this step.
Execute below command to start minikube:
minikube start --vm-driver hyperv --hyperv-virtual-switch "Minikube Virtual Switch"
NOTE: If your virtual switch name is different then
Minikube Virtual Switch, you can replace that in above command.
What above command will do is it will download minikube ISO from internet and use that ISO to setup small contained virtual machine in Hyper-V environment. It will also download required kubernetes system containers to manage kubernetes cluster.
Once minikube has started, you will receive below output and you are ready to execute kubernetes command and deploy a container.
o minikube v0.35.0 on windows (amd64) > Creating hyperv VM (CPUs=2, Memory=2048MB, Disk=20000MB) ... @ Downloading Minikube ISO ... 184.42 MB / 184.42 MB [============================================] 100.00% 0s - "minikube" IP address is 192.168.0.106 - Configuring Docker as the container runtime ... - Preparing Kubernetes environment ... @ Downloading kubeadm v1.13.4 @ Downloading kubelet v1.13.4 : Waiting for pods: apiserver proxy etcd scheduler controller addon-manager dns - Configuring cluster permissions ... - Verifying component health ..... + kubectl is now configured to use "minikube" = Done! Thank you for using minikube!
To check if you have successful connection to kubernetes cluster execute below command from PowerShell console.
kubectl get pods -n kube-system
NAME READY STATUS RESTARTS AGE coredns-86c58d9df4-87cj9 1/1 Running 0 3m5s coredns-86c58d9df4-bg64j 1/1 Running 0 3m5s etcd-minikube 1/1 Running 0 2m9s kube-addon-manager-minikube 1/1 Running 0 2m16s kube-apiserver-minikube 1/1 Running 0 2m20s kube-controller-manager-minikube 1/1 Running 0 2m14s kube-proxy-wnxk4 1/1 Running 0 3m5s kube-scheduler-minikube 1/1 Running 0 2m23s storage-provisioner 1/1 Running 0 2m4s
Deploying your first container
To deploy your first container in your minikube cluster, execute deploy commmand.
kubectl create deployment hello-world --image=kitematic/hello-world-nginx
The above command will pull new image from docker hub a public registry and run a container in your minikube kubernetes cluster.
To check status of a container, execute below command.
kubectl get pods
PS C:\Users\Ray> kubectl get pods NAME READY STATUS RESTARTS AGE hello-world-7cbc87684d-pmwxl 1/1 Running 0 4m50s
Accessing your hello-world app
In order to access your
hello-world application outside kubernetes cluster, you need to expose it as a service.
kubectl expose deployment hello-world --port=80 --type=NodePort
Once the service has been created, you will need to get a port number of your exposed service to be able to browse the application. Execute below command.
kubectl.exe get services
PS C:\Users\Ray> kubectl.exe get services NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE hello-world NodePort 10.96.79.70 <none> 80:31548/TCP 8m9s kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 21h
When you expose a service, kubernetes will automatically create a port number randomly. In my case it is
hello-world application. I will append this at the end of the minikube node ip address to access the application.
To get minikube IP address, execute below command:
In my case I received
192.168.0.112. I will use this IP address to access the application as shown in below screenshot.
Kubernetes provides free dashboard to also manage your cluster via UI. To access kubernetes dashboard, you will need to execute below minikube command.
You will see below output upon initialization.
PS C:\Users\Ray\Downloads> minikube.exe dashboard - Enabling dashboard ... - Verifying dashboard health ... - Launching proxy ... - Verifying proxy health ... - Opening http://127.0.0.1:53782/api/v1/namespaces/kube-system/services/http:kubernetes-dashboard:/proxy/ in your default browser...
Once the initialization is completed, the dashboard should open in your default browser. If it didn't open you can browse it by opening this link
You are all set! You can now navigate the dashboard and get familiar with pods, services, and many more.
Thank you for following this tutorial! Hope this helped you get started with kubernetes.