Rancher Desktop is a free, open-source, cross-platform desktop application that makes it easy to develop and test applications in Kubernetes. Rancher Desktop provides a simple and intuitive graphical user interface (GUI) for managing Kubernetes clusters on your local machine, including the ability to create, modify, and delete clusters with just a few clicks.
It includes features like Helm chart management, support for popular Kubernetes tools like kubectl and Stern, and integration with other Rancher products and services. One of the key benefits of Rancher Desktop is that it simplifies setting up a Kubernetes development environment on your local machine, regardless of your operating system or existing toolset.
It supports multiple Kubernetes distributions, including Kubernetes and distributions like K3s and Rio. It also includes pre-configured templates for common application stacks, making developing and testing Kubernetes-based applications easy.
Table of Contents
Requirements
- A computer with virtualization capabilities enabled, such as AMD-V or Intel VT-x.
- Windows 10 build 1909 or higher. This tutorial uses Windows 10 22H2 build 19045.
- 4 CPUs and 8GB RAM (recommended). Rancher may work with lower specifications but might suffer performance degradation.
- Administrator access to the local machine.
- Visual Studio Code or any code editor you prefer.
Rancher Desktop Utilities
The Rancher Desktop installation comes with access to the following supporting utilities.
- Helm — Package manager for Kubernetes.
- kubectl — The command line tool to manage Kubernetes.
- nerdctl — A Docker-compatible command line tool for containerd.
- Moby — A framework to assemble specialized container systems.
- Docker Compose — A tool for defining and running multi-container Docker applications.
We’ll be using nerdctl and kubectl the most in our examples.
Installing Rancher Desktop on Windows 10
Once you’ve met the requirements, let’s start installing Rancher Desktop.
- Open the Rancher Desktop website in your browser.
- Scroll down to the Download Rancher Desktop section and click the Download Windows link. This link ensures that you’re downloading the latest release. As of this writing, the latest Rancher Desktop version is 1.8.1.
- Once downloaded, open the installer.
- Accept the Rancher Desktop License Agreement and click Next.
- On the next page, click Install.
Note. Rancher Desktop requires Windows Subsystem for Linux 2 (WSL2), which will be installed automatically.
- Wait for the installation to finish.
- Once installed, click Finish.
- When asked to restart the computer, click Yes.
- Once the computer has restarted, launch Rancher Desktop.
- During the initial launch, Rancher Desktop asks you to choose the Kubernetes version and container runtime. Leave the default to use the latest Kubernetes available and containerd as the runtime, and click Accept.
- Rancher Desktop starts downloading components and starting services. Wait until it is complete.
Building Images and Running Containers using NERDCTL
In this section, let’s use NERDCTL to build a sample image in the default namespace.
- Let’s create a dedicated folder for this demo image and open it in Visual Studio Code:
mkdir ~/demo cd ~/demo code .
- Next, create a new Dockerfile file.
- Copy the below code and paste it into the Dockerfile file.
FROM alpine CMD ["echo", "This is a demo image build."]
This Dockerfile will build an image using Alpine as the base and display string This is a demo image build on the screen when the application is run.
- Next, run the below code in the terminal to build the image. This command also tags the image using the –tag flag. The dot (.) at the end tells NERDCTL to read the Dockerfile on the current directory.
nerdctl build --tag demo:v1.0 .
- List the images in the default namespace by running this command:
nerdctl images
As you can see below, the new image has been built and is available.
- Now, let’s run a container based on this image. Like in Docker, the –rm flag automatically removes the container after it exits.
nerdctl run --rm demo:v1.0
Deploying Containers to Kubernetes
In the previous section, we built an image to the default namespace. To deploy containers in Kubernetes, the image must be in the k8s.io namespace instead.
For this to work, ensure that the container engine (runtime) selected in Rancher Desktop is containerd.
Once you’ve confirmed the correct runtime, let’s begin with the image build. In this example, we’ll deploy an Apache Server to Kubernetes.
- Create a new folder to contain our build files and open it in Visual Studio Code.
mkdir ~/apache cd ~/apache code .
- Create an empty Dockerfile and copy the below code.
FROM ubuntu RUN apt-get update && \ apt-get install apache2 -y && \ apt-get install apache2-utils -y && \ apt-get clean EXPOSE 80 CMD ["apache2ctl", "-D", "FOREGROUND"]
Here’s what each instruction in this Dockerfile does:
- FROM ubuntu: This instruction sets the base image as Ubuntu. This means that Docker will start with a basic Ubuntu image and then build the Apache web server on top of it.
- RUN apt-get update: This instruction updates the package index on the Ubuntu image.
- apt-get install –y apache2: This instruction installs the Apache web server on the Ubuntu image.
- apt-get install –y apache2-utils: This instruction installs the Apache utility programs on the Ubuntu image.
- apt-get clean: This instruction removes any temporary files or packages used during the previous installation steps. This helps to reduce the size of the final Docker image.
- EXPOSE 80: This instruction tells Docker that the container will listen on port 80, the default HTTP traffic port.
- CMD [“apache2ctl”, “-D”, “FOREGROUND”]: This instruction specifies the default command that should be executed when the container starts. In this case, it starts the Apache web server and runs it in the foreground. The D FOREGROUND option ensures that the Apache process does not run in the background, allowing the engine to monitor it and keep the container running.
- Run this command to build the image under the k8s.io namespace (so it can run in Kubernetes).
nerdctl --namespace k8s.io build --tag apache_demo:latest .
- Confirm the image exists in the k8s.io namespace.
nerdctl images --namespace k8s.io
- The image is built and ready, so let’s use it and run the Apache server. The command kubectl is the tool used to create the Kubernetes deployment.
kubectl run my-apache --image=apache_demo:latest --image-pull-policy=Never --port=80
Here is a breakdown of each part of the command:
- kubectl: This is the name of the command-line tool used to create the Kubernetes deployment.
- run my-apache: This creates a new deployment named my-apache.
- -image=apache_demo:latest: This specifies the container image that will be used to create the deployment. In this case, the image is apache_demo with the latest tag.
- -image-pull-policy=Never: This sets the image pull policy to Never, which means that Kubernetes will not try to pull a newer version of the image from a container registry. Instead, it will use the image already present on the cluster nodes.
- -port=80: This specifies that the container will listen on port 80.
- Next, let’s forward the hosts’ port 8080 to the container’s port 80 so we can access the Apache web server outside the cluster.
kubectl port-forward pods/my-apache 8080:80
Here is a breakdown of each part of the command:
- port-forward: This is the subcommand used to forward network traffic to a container in a pod.
- pods/my-apache: This specifies the pod’s name and the container to which the traffic will be forwarded. In this case, the pod is named my-apache, and the container is the default container within the pod.
- 8080:80: This specifies the local and remote ports that will be used for the port forwarding. Traffic sent to port 8080 on the local machine will be forwarded to port 80 on the container within the my-apache pod.
- Open a new browser window and access the application at:
HTTP://localhost:8080
Conclusion
In this blog post, we’ve covered the basics of getting started with Rancher Desktop, including how to download and install the application, build images, and deploy them in Kubernetes.
Whether you’re a seasoned Kubernetes developer or just getting started with the platform, Rancher Desktop is a tool worth exploring. Its intuitive interface, powerful features, and a robust ecosystem of integrations and extensions can help streamline your development workflows, increase productivity, and bring your Kubernetes-based applications to market faster and more efficiently.