This README provides a complete guide to setting up a local Kubernetes environment using MicroK8s, installing Helm for Kubernetes package management, and deploying a Helm chart.
Follow the steps below to install and configure the necessary tools and deploy a Kubernetes application with Helm.
- Windows Subsystem for Linux (WSL) installed on Windows.
- Ubuntu environment running under WSL.
- Kubernetes installed in your system.
Multipass allows you to create and manage virtual machines on your local machine, useful for managing Kubernetes clusters in virtualized environments.
To install Multipass:
-
Open your Ubuntu terminal under WSL and install Multipass using Snap:
sudo snap install multipass
-
Once the installation is complete, check if any virtual machines (VMs) are running by executing the following command:
multipass list
If no instances are listed, it means no virtual machines are running, and you can proceed with the installation of MicroK8s.
MicroK8s is a lightweight Kubernetes distribution suitable for local environments.
To install MicroK8s:
-
Run the following command to install MicroK8s:
sudo snap install microk8s --classic
-
Once the installation is complete, verify that MicroK8s is up and running by checking its status:
microk8s status --wait-ready
This command will wait until MicroK8s is fully initialized and ready for use.
Now that MicroK8s is installed, you can enable the Kubernetes Dashboard for easier cluster management.
To enable the Kubernetes Dashboard:
-
Run the following command to enable the dashboard:
microk8s enable dashboard -
Once the dashboard is enabled, you can access it by running:
sudo microk8s dashboard-proxy
This will create a proxy and provide you with a URL (e.g.,
http://127.0.0.1:8001) to access the dashboard in your browser. Along with the URL, a token will be generated that you will need to log into the dashboard later.
To run another local Kubernetes cluster, you can install Minikube. This allows you to have multiple Kubernetes clusters running in parallel.
To start Minikube:
-
Open another terminal window or tab, and start Minikube by running:
minikube start
This will set up a separate local Kubernetes environment alongside MicroK8s. You can switch between MicroK8s and Minikube as needed.
Helm is a package manager for Kubernetes, making it easier to deploy and manage applications.
To install Helm on Windows:
-
Go to the official Helm Releases page.
-
Download the latest release for Windows. Choose the appropriate zip file for your architecture (e.g.,
helm-v3.x.x-windows-amd64.zip). -
Once the zip file is downloaded, unzip it and move the
helm.exebinary to a directory of your choice (e.g.,C:\helm\). -
To verify the installation, run the following command in your terminal:
helm version
This will output the version information for Helm, confirming the installation was successful.
Now that Helm is installed, let's create a simple Helm chart to deploy an application.
To create a Helm chart:
-
Use the following command to create a new Helm chart called
helloworld:helm create helloworld
-
Navigate to the
helloworlddirectory:cd helloworld -
Open the
values.yamlfile in a text editor to modify the configuration:notepad values.yaml
-
In the
values.yamlfile, change theservice.typefromClusterIPtoNodePortto expose the service on a specific port outside the Kubernetes cluster:service: type: NodePort
Save the file after making this change.
After modifying the values.yaml file, you can install the Helm chart and deploy it on your Kubernetes cluster.
To install the Helm chart:
-
Run the following command to install the chart with the name
myhelloworld:helm install myhelloworld helloworld
-
To verify that the chart was installed successfully, list all installed charts:
helm list -a
-
You can also check the deployed services by running:
kubectl get services
To access the Nginx application running inside the Kubernetes cluster, you need to forward the port from the Kubernetes pod to your local machine.
To set up port forwarding:
-
First, find the pod associated with your deployed service:
kubectl get pods
-
Then, forward the port to your local machine by running the following command. Replace
<your-pod-name>with the actual pod name from the previous command:kubectl port-forward pod/<your-pod-name> port:Nodeport
This will forward port
porton your local machine to port Nodeport on the Kubernetes pod. -
You can now access the application by navigating to
http://localhost:portin your web browser.
To update the ReplicaSet from 1 to 2 and redeploy the application, follow these steps:
-
Open the
values.yamlfile again:notepad values.yaml
-
Find the
replicaCountsection and change the value from1to2:replicaCount: 2
-
Save the
values.yamlfile.
To apply the updated replica count and redeploy the application, use the following Helm upgrade command:
helm upgrade myhelloworld ./helloworldTo verify that the update was successful:
- Check the deployed pods:
kubectl get podsYou should now see 2 pods running for your application, reflecting the updated replica count.
- Check the ReplicaSet to ensure that the number of replicas is correctly updated:
kubectl get replicasetYou should see the ReplicaSet with 2 replicas.
To access the Nginx application running inside the Kubernetes cluster, you need to forward the port from the Kubernetes pod to your local machine.
To set up port forwarding:
- First, find the pod associated with your deployed service:
kubectl get pods- Then, forward the port to your local machine by running the following command. Replace with the actual pod name from the previous command:
kubectl port-forward pod/<your-pod-name> port:Nodeport- You can now access the application by navigating to the link http:127.0.0.1:port in your web browser.
After running sudo microk8s dashboard-proxy, you will see a URL (e.g., http://127.0.0.1:port). Open this URL in your browser to access the Kubernetes dashboard.
You do not need to manually retrieve the token, as it will automatically be generated when you run the dashboard-proxy command.
-
Copy the token and paste it into the dashboard login screen.
-
Once logged in, you can view the deployed Helm application and monitor its status in the deployment workspace.
By following the steps outlined above, you have:
- Installed Multipass, MicroK8s, and Minikube for local Kubernetes environments.
- Installed Helm for managing Kubernetes applications.
- Created and deployed a simple Helm chart (
helloworld). - Accessed the application via port forwarding and the Kubernetes dashboard.
Now you can use Helm to manage your Kubernetes applications, and explore further Kubernetes features and charts.