Kubernetes is made for managing your cloud resources and build scalable apps. It's considered the most popular tool for automating, deploying, and scaling your whole cloud. It runs on all major operating systems and it is the most popular open source tool in the cloud market. Kubernetes can scale your whole infrastructure, check the health of each service, work as a load balancer, automate deployments and many more. You can install & setup as many nodes (clusters) as you want, and deploy your pods (docker containers) and services across the cloud. In this tutorial you will learn how to setup Kubernetes and deploy the official web GUI dashboard where you can manage and monitor everything but first you have to install Hyper-V & Docker in order to use Kubernetes.
Windows as we all know, have their own virtualization software and it's called Hyper-V which is basically something like VirtualBox on steroids. Hyper-V can manage your virtual machines (VM) using the default GUI tool provided by Microsoft for free, or through command line. Enabling Hyper-V can be easily done but first, make sure your PC meets the following requirements: Your OS should be Windows 10 (Enterprise, Pro or Education) with minimum 4GB RAM and CPU Virtualization support, although you have to double check if it's enabled in your BIOS settings.
You can remove or add features that don't come up pre-installed during the installation of Windows, like Hyper-V. Always remember that some of the features require internet access to download extra components from Windows Update. Follow the next steps to enable Hyper-V on your machine.
- Go to Control Panel
- On your left panel, click on Programs
- Then click Programs and Features followed by Turn Windows features on and off.
- Check Hyper-V and Windows Hypervisor Platform
- Click OK
Your system will now start installing Hyper-V on the background, it may need to reboot a couple of times until everything is configured properly. Don't expect any notification or something! Run the following powershelgl command as Administrator and verify if Hyper-V is installed successfully on your machine:
Get-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V
PS C:\Windows\system32> Get-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V FeatureName : Microsoft-Hyper-V DisplayName : Hyper-V Platform Description : Provides the services that you can use to create and manage virtual machines and their resources. RestartRequired : Possible State : Enabled
Kubernetes is build on top of Docker, theoretically is just a tool that communicate with your Docker containers and manage everything on enterprise level. To install Docker just grab & run the following installer https://desktop.docker.com/win/main/amd64/Docker%20Desktop%20Installer.exe . During installation Docker will ask you to choose between Hyper-V and WSL. For better security uncheck WSL 2. Docker will setup a Linux virtual machine on top of Hyper-V and start all the necessary services without manually configure anything. After the installation, you can either "communicate" with Docker using the CLI tool
docker or running HTTP requests though its API.
Docker comes with a handy GUI tool where you can modify some settings or install & enable Kubernetes. Follow the following instructions, WARNING! If Docker is installed successfully and you can't locate its tray icon, you have to reboot your system. If the problem persists, check the official troubleshooting guide here https://docs.docker.com/docker-for-windows/troubleshoot/. Now follow the instructions to install Kubernetes.
- Right-click the Docker tray icon
- Click "Settings"
- On the left panel click "Kubernetes"
Enable Kubernetesand click "Apply"
*** If you're behind a firewall, don't forget to allow:
C:\program files\docker\docker\frontend\docker desktop.exe C:\program files\docker\docker\resources\com.docker.backend.exe C:\program files\docker\docker\resources\bin\kubectl.exe C:\program files\docker\docker\resources\com.docker.vpnkit.exe
During installation, Docker is going to install additional packages and dependencies. It may take around 5~10 minutes and the installation time depends on your Internet speed and your PC performance. Wait until the 'Installation complete!' popup message is shown up. After installing Kubernetes you can make sure that everything is working fine using the Docker app. If both services (Docker & Kubernetes) are running successfully without any errors then both icons at bottom left will go green.
Kubernetes Dashboard is the official web-based UI where you can manage Kubernetes resources. It's not installed by default. Deploying applications with Kubernetes can be easily managed using the cli tool called
kubectl where you can interact with your cloud and manage your Pods, Nodes, or Clusters. If you pass the
apply argument followed by your YAML configuration file you can easily create or update Kubernetes resources. Run the following commands to deploy & enable the Kubernetes Dashboard using the following commands.
- Go to https://github.com/kubernetes/dashboard/releases
- Scroll down to
Installationand download latest yaml configuration file for example https://raw.githubusercontent.com/kubernetes/dashboard/v2.6.0/aio/deploy/recommended.yaml
- Deploy it using
kubectl apply -f .\recommended.yaml
- Verify that it's running using the following command:
kubectl.exe get -f .\recommended.yaml.txt
PS C:\Users\user\Desktop> kubectl.exe get -f .\recommended.yaml.txt
NAME STATUS AGE
namespace/kubernetes-dashboard Active 2m10s
NAME SECRETS AGE
serviceaccount/kubernetes-dashboard 1 2m10s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/kubernetes-dashboard ClusterIP 10.97.3.127 <none> 443/TCP 2m9s
There are two ways to access the dashboard with tokens, the first one (deprecated, works only for older versions) is using the default token that was crated during the installation of Kubernetes and the second (more secure) way is by creating users, giving them permissions, and then get the generated token.
Create a new configuration file:
apiVersion: v1 kind: ServiceAccount metadata: name: admin-user namespace: kubernetes-dashboard --- apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata: name: admin-user roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole name: cluster-admin subjects: - kind: ServiceAccount name: admin-user namespace: kubernetes-dashboard
Deploy it using
kubectl.exe apply -f .\dashboard-admin.yaml.txt
Generate token using
kubectl.exe -n kubernetes-dashboard create token admin-user
- Run the following command powershell (not cmd)
((kubectl -n kube-system describe secret default | Select-String "token:") -split " +")
- Copy the generated token
- Open the following link on your browser: http://localhost:8001/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/
Token& paste the generated token
- Sign In
If everything is configured properly you'll be able to see the dashboard and your cloud resources. From there you can do almost all the "hard" work without dealing with the CLI every time. You may sometimes get your hands dirty with the command line but if you don't understand the concept of Docker and Kubernetes or you don't have time to for maintaining your own cloud, it's better to stick with some PaaS providers that can cost you a fortune.
If you liked this article please follow me on Twitter :)