The Complete Handbook to Install Kubernetes Like a Pro

how to install kubernetes

Kubernetes, commonly abbreviated as K8s, is an open-source and portable platform that is used for managing containerized workloads and services. It organizes application components into logical units, such as pods, services, and deployments, for easier management and discovery. Moreover, it facilitates both declarative configuration and automation. Hence, Kubernetes has become the de facto standard for container orchestration, with a rapidly growing ecosystem and strong community support. Originally designed by Google, the project is now maintained by a worldwide community of contributors under the Cloud Native Computing Foundation (CNCF).  

Why Does One Require Kubernetes? 

Containers are, in general, a good way to bundle and run your applications. Kubernetes provides a framework that enables you to run distributed systems resiliently. For instance, if one container goes down, Kubernetes can automatically restart it to maintain availability. Additionally, Kubernetes takes care of scaling and failover for your application, and it also provides deployment patterns. 

Kubernetes provides you with: 

  • Service discovery and load balancing 
  • Storage orchestration 
  • Automated rollouts and rollbacks 
  • Automatic bin packing 
  • Secret and configuration management 
  • Batch execution 
  • Horizontal scaling 
  • Self-healing capabilities 
  • Designed for extensibility 

How to Install Kubernetes? 

Before installing Kubernetes in your system, make sure that the below-mentioned hardware and software requirements are met: 

Hardware Requirements: 

Requirements may vary based on actual workload needs 

  • Master node (Control plane node) with at least 2GB memory and 2CPU cores (this may vary depending on the cluster size) 
  • Worker node with 1GB memory and 1CPU core 

Software Requirements: 

  • Hyper-V (for Windows Professional editions) 
  • Docker Desktop (for setting up Kubernetes on Windows, especially for Windows Home users) 
  • Unique product UUID for every node (although this is not typically listed as a basic requirement, it’s good to ensure node uniqueness) 

These are minimal requirements for a small, non-production cluster. For production use, you may need significantly more resources, depending on the workload. 

Additional Libraries: 

  • Enable Hyper-V (for Windows Professional editions) or WSL2 (for Windows Home users) 
  • Enable Kubernetes support in Docker Desktop 
  • Ensure all the required libraries and tools are installed beforehand to facilitate proper Kubernetes usage 
  • Ensure that there is a full range of connectivity between all the machines in the cluster 

Install and Setup Hyper-V 

Windows has its virtualization software, known as Hyper-V. It allows you to manage your virtual machines using either the free Microsoft GUI or the command line. In Windows Home Edition, Hyper –V is not available. Windows Home users should use WSL 2. 

To enable Hyper-V on your machine: 

  1. Open the Control Panel 
  2. Select Programs from the left panel 
  3. Go to Programs and Features 
  4. Click on “Turn Windows Features on or off” 
  5. Check both Hyper-V and the Hypervisor Platform  
  6. Select OK 

Your system should now begin installing Hyper-V in the background. You might need to reboot your system a couple of times until everything is properly configured.  

Make sure to verify that Hyper-V has been successfully installed on your machine. You can do that by running the following command as Administrator in PowerShell: 

powershell 

 Get-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V-All 

Once the state shows Enabled for the above command in PowerShell, you are good to proceed. 

Download and Install Docker  

Kubernetes is a container orchestration system that can use Docker as one of its container runtimes. Windows 10 users can use Docker Desktop, which is a version of Docker optimized for Windows 10. However, it should be noted that Docker Desktop includes Docker and Kubernetes. You don’t need to install Kubernetes separately if you use Docker Desktop with Kubernetes enabled. Users should sign up for Docker Hub and log in via Docker Desktop 

Installation of Docker Desktop: 
  1. Download Docker Desktop from the official Docker website. 
  2. Double-click Docker for Windows Installer to run the installer 
  3. The docker starts automatically once the installation is complete. Docker is accessible from a terminal. You can verify it is running by the whale icon in the notification area. 
Verifying Docker installation: 
  1. Open a command-line terminal such as PowerShell 
  1. In order to check the version, run: 
docker version 
  1. To verify that Docker can pull and run images, run: 
docker run hello-world 

As long as this is running, Docker can be accessed from any terminal.  

Enabling Kubernetes on Docker Desktop might require elevated permissions and additional configurations on corporate networks or restricted environments. 

Install Kubernetes 

Docker has a GUI tool that allows you to install and enable Kubernetes. To install Kubernetes: 

  1. Right-click the Docker tray icon and select “Settings” 
  1. In the settings menu, select “Kubernetes” from the left panel 
  1. Check the box next to “Enable Kubernetes” and click “Apply” 

Docker will install additional packages during the process. It typically takes about 5-10 minutes to install. However, this may vary depending on your system and network speed. Once you see the message “installation completed!” on your screen, you can be sure that Kubernetes has been installed.  

Install Kubernetes Dashboard 

The official web-based UI for managing Kubernetes resources is the Kubernetes Dashboard. However, it is not set by default. Kubernetes applications can be easily deployed using the command line tool “kubectl”, which basically allows you to interact with your cloud and manage your Pods, Nods, and Clusters. 

You can use the following commands to deploy and enable the Kubernetes Dashboard: 

  1. Get the yaml configuration and apply it using “kubectl”: 
kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.0/aio/deploy/recommended.yaml 

            to deploy it 

  1. Run the following command to see if the Dashboard is running 
kubectl get pods -n kubernetes-dashboard 

Access the Dashboard 

You can access the dashboard by either using the default token created using Kubernetes installation, or by creating users, giving them permissions, and receiving the generated token. 

To use the default token created using Kubernetes installation: 

  1. Run the following command to get the secret name and retrieve the token: 
       kubectl -n kubernetes-dashboard get secret 

Identify the appropriate secret from the lost (usually named “kubernetes-dashboard-toaken-<suffix>), then run: 

       kubectl -n kubernetes-dashboard describe secret <your-secret-name> 

Copy the generated token 

  1. Start the kubectl proxy: 
kubectl proxy 
  1. Open the following link on your browser 

http://localhost:8001/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy

  1. When prompted, select the token option and paste the generated token 
  1. Click “Sign In” 

You will be able to see the dashboard and your Kubernetes resources if everything is set up.  

HOW TO INSTALL KUBECTL FOR WINDOWS? 

To begin Kubernetes installation on Windows, you will first need to install Kubectl. Here, we’ll look at installing Kubectl binary using Curl on Windows. 

Download kubectl 1.30.0 

Download the specific version 1.30.0 of kubectl using the following command in PowerShell 

curl.exe -LO "https://dl.k8s.io/release/v1.30.0/bin/windows/amd64/kubectl.exe" 

However, if you don’t have Curl installed, you can download it from the official website and follow the installation instructions. 

Validate the Binary 

Before using the downloaded kubectl binary, it is essential to verify its integrity to ensure it has not been tampered with during download. 

  • Download the kubectl checksum file: 
curl.exe -LO "https://dl.k8s.io/v1.30.0/bin/windows/amd64/kubectl.exe.sha256
 

Validate the kubectl binary against the checksum file using PowerShell: 

  • Using Command Prompt to manually compare CertUtil’s output to the checksum file downloaded: 
CertUtil -hashfile .\kubectl.exe SHA256 

Compare the output hash with the hash provided in the checksum file 

  • Using PowerShell to automate the verification using the -eq operator to get a True or False result: 
$DownloadedHash = (Get-FileHash -Algorithm SHA256 .\kubectl.exe).Hash 
$ExpectedHash = Get-Content .\kubectl.exe.sha256 
$DownloadedHash -eq $ExpectedHash 
Append or prepend the kubectl binary folder to your PATH environment variable 

To use kubectl from any command prompt or PowerShell window, you need to add its location to your PATH environment variable. 

Open System Properties 
  • Press “Win + X” and select System 
  • Click on “Advanced system settings” on the left panel 
  • In the “System Properties” window, click on the “Environment Variables” button 
Modify the PATH Variable 
  • In the “Environment Variables” window, find the Path variable in the “System variables” section and select it 
  • Click “Edit” 
  • In the “Edit Environment Variable” window, click “New”. Add the path to the folder where you downloaded “kubectl.exe”. For example; “C: \path\to\your\kubectl\folder” 
  • Click “OK” to close all the windows 
Make Sure to Ensure That the Version of kubectl is the Same as Downloaded 

To ensure that the version of kubectl you installed matches the version you downloaded, run the following command in your command prompt or PowerShell: 

kubectl version –client 

This command will display the client version of kubectl. Make sure to verify that it matches the version you downloaded (v1.30.0) 

These steps ensure that kubectl is properly downloaded, validated, made executable, moved to an accessible location, and verified for correct installation. 

How to Instal Kubectl for Mac OS? 

To begin Kubernetes installation on MacOS, you will first need to install Kubectl. Here, we’ll look at installing Kubectl binary using Curl on MacOS. 

Download the Latest Release 

Open your terminal and run the following command to download the latest stable release of kubectl:    

curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/darwin/amd64/kubectl" 
Validate the Binary  
  • Download the kubectl checksum file: 
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/darwin/amd64/kubectl.sha256" 
  • Validate the kubectl binary against the checksum file: 
echo "$(cat kubectl.sha256) kubectl" | shasum -a 256 --check 
  • If valid, the output will be: 
kubectl: OK 
  • Shasum will exit with nonzero status and will print output similar to the following, if the check fails: 
kubectl: FAILED 
shasum: WARNING: 1 computed checksum did NOT match 
Make the kubectl Binary Executable 
chmod +x ./kubectl 
Move the kubectl Binary to a File Location on Your System PATH 
sudo mv ./kubectl /usr/local/bin/kubectl 
sudo chown root: /usr/local/bin/kubectl 

Ensure to use the correct PATH for common directories 

Verify the Installation 

To ensure the version of kubectl you installed is correct, run the following command: 

kubectl version –client 
After the Installation and Validation, Delete the Checksum File 
rm kubectl.sha256 

These steps ensure that kubectl is properly downloaded, validated, made executable, moved to an accessible location, and verified for correct installation. 

How to Install Kubectl for Linux? 

To begin Kubernetes installation on Linux, you will first need to install Kubectl. Here, we’ll look at installing Kubectl binary using Curl on Linux. 

Download the Latest Release with the Command  

Open your terminal and run the following command to download the latest stable release of kubectl: 

curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl
Validate the Binary 
  • Download the kubectl checksum file: 
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl.sha256
  • Validate the kubectl binary against the checksum file: 
echo "$(cat kubectl.sha256) kubectl" | sha256sum –check 
  • If valid, the output is 
Kubectl: OK 
  • sha256 will exit with a nonzero status and will print output similar to the following if the check fails: 
kubectl: FAILED 
sha256sum: WARNING: 1 computed checksum did NOT match 
Install kubectl 

Install the kubectl binary to a directory in your PATH: 

sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl 
Test to Ensure the Version You Installed is Up-to-Date 

To ensure the version of kubectl you installed is correct, run the following command: 

kubectl version –client 

These steps ensure that kubectl is properly downloaded, validated, made executable, moved to an accessible location, and verified for correct installation. 

Troubleshooting 

Certain troubleshooting steps, in case you face difficulties: 

Check for Pod Errors 

List all pods across all namespaces to identify any errors 

kubectl get pods --all-namespaces 
Describe a Problematic Pod 

Get detailed information about a specific pod to diagnose issues 

kubectl describe pod <pod-name> -n <namespace> 

Check Logs for Errors 

View the logs of a specific pod to look for error messages 

kubectl logs <pod-name> -n <namespace> 
Ensure no Image Pull Errors 

Check for events indicating failed image pulls across all namespaces 

kubectl get events --all-namespaces | grep Failed 

Note: Replace “<pod-name>” with the actual name of the pod and “<namespace>” with the relevant namespace in your Kubernetes cluster 

Conclusion

Using this step-by-step guide on how to install Kubernetes and Kubectl, you should be able to get through the process with ease. However, it may prove to be a little time-consuming.  

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top