Introduction
Setting up a Kubernetes environment is the first step in learning how to deploy and manage containerized applications. This chapter will guide you through setting up a local Kubernetes cluster using Minikube and provide an overview of cloud-based Kubernetes setups using managed services like GKE, EKS, and AKS.
Table of Contents
Local Setup with Minikube
Minikube is a tool that allows you to run a single-node Kubernetes cluster on your local machine. It is ideal for learning, testing, and development purposes.
Installing Minikube
To install Minikube, follow these steps:
-
Install Minikube: Download and install minikube from the official minikube website. Ensure to download the version that is compatible with your operating system (Linux, Windows, or MacOS) and architecture. If you are using a MacOS or Linux operating system, you can find out the architecture of your system using the command below:
uname -m
If you are using Windows, you can find out the architecture of your system by opening your PowerShell terminal as an administrator and running the command below:
```sh
wmic os get osarchitecture
```
Alternatively, you can also run the command below to find out the architecture of your Windows machine:
```sh
systeminfo | findstr /C:"System Type"
```
After installing minikube, you can verify if the installation was successful through the command below:
```sh
minikube version
```
If there is no output, it means the installation wasn't successful.
Installing Kubectl
kubectl
is a command-line tool for interacting with your Kubernetes cluster. Follow these steps to install kubectl
:
- Download the latest release with the command:
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
- Make the kubectl binary executable:
chmod +x kubectl
- Move the binary in to your PATH:
sudo mv kubectl /usr/local/bin/
- Verify the installation of kubectl and also check the version installed through the command below:
kubectl version --client
- Configure kubectl to interact with your Minikube cluster.
kubectl config use-context minikube
- Next, start your Minikube cluster with the command below:
minikube start
The command above will start a virtual machine and set up a Kubernetes cluster within it. The command also automatically uses Docker as the default driver for Minikube (that is if Docker is installed). Other drivers that Minikube can use include VirtualBox, VMware, HyperKit, and Podman. To specify a specific driver (e.g., VirtualBox), use the "-driver" flag.
minikube start --driver=VirtualBox
Once your Minikube cluster is up and running, run the command below to verify that everything is working perfectly:
kubectl get nodes
If everything is working perfectly, the command above should display a single node with the status "Ready".
- To stop your Minikube cluster, run:
minikube stop
- If you want to delete your minikube cluster, use the command below:
minikube delete
Cloud-based Kubernetes Setup
For production environments, it is recommended to use managed Kubernetes services offered by cloud providers. These services handle the complexity of setting up and managing Kubernetes clusters, allowing you to focus on deploying and managing your applications. One important point you should note is that unlike Minikube, which is free, cloud-based Kubernetes setups incur costs and you will be billed accordingly. Here are three popular managed Kubernetes services:
Google Kubernetes Engine (GKE)
Google Kubernetes Engine (GKE) is a managed Kubernetes service provided by Google Cloud Platform. It offers automatic updates, scaling, and a highly available control plane. To get started with GKE, you need a Google Cloud
Platform account with billing enabled and the gcloud tool installed. Once you have gcloud installed, follow the remaining steps below to set up your GKE cluster:
- Set a Default Zone:
gcloud config set compute/zone us-west1-a
- Create a GKE Cluster:
gcloud container clusters create my-cluster --zone us-central1-a
- Get Authentication Credentials:
gcloud container clusters get-credentials my-cluster --zone us-central1-a
- Deploy an Application:
kubectl create deployment hello-gke --image=gcr.io/google-samples/hello-app:1.0
kubectl expose deployment hello-gke --type=LoadBalancer --port 80 --target-port 8080
Amazon Elastic Kubernetes Service (EKS)
Amazon Elastic Kubernetes Service (EKS) is a managed Kubernetes service provided by Amazon Web Services (AWS). It integrates with other AWS services, providing a secure and scalable environment for running Kubernetes clusters.
Before getting started with EKS, first install the open source eksctl
command-line tool. Once you have eksctl installed and in your path, follow the remaining steps below to set up your EKS cluster:
- Create an EKS Cluster:
eksctl create cluster --name my-cluster --region us-west-2
- Configure kubectl:
aws eks --region us-west-2 update-kubeconfig --name my-cluster
- Deploy an Application:
kubectl create deployment hello-eks --image=amazon/amazon-ecs-sample
kubectl expose deployment hello-eks --type=LoadBalancer --port 80
Azure Kubernetes Service (AKS)
Azure Kubernetes Service (AKS) is a managed Kubernetes service provided by Microsoft Azure. It offers integrated CI/CD capabilities and security features. Before getting started with AKS, first install the az CLI. Once you have installed az CLI, follow the remaining steps below to set up your AKS cluster:
- Create an AKS Cluster:
az aks create --resource-group myResourceGroup --name myAKSCluster --node-count 1 --enable-addons monitoring --generate-ssh-keys
- Get AKS Credentials:
az aks get-credentials --resource-group myResourceGroup --name myAKSCluster
- Deploy an Application:
kubectl create deployment hello-aks --image=nginx
kubectl expose deployment hello-aks --type=LoadBalancer --port 80
Conclusion
Setting up Kubernetes can be done locally using Minikube for learning and development, or using managed Kubernetes services for production environments. Whether you choose a local setup or a cloud-based setup, Kubernetes provides a robust platform for managing containerized applications at scale.
Feel free to leave comments and share this article. Follow my blog for more insights on Kubernetes!
Top comments (0)