How to Set Up a Kubernetes Cluster with Rancher

July 1, 2021

Introduction

Rancher provides an interface for application deployment and cluster maintenance in Kubernetes. The tool gives DevOps teams a complete software stack for managing containerized apps. With Rancher, Kubernetes can be run anywhere - in a data center or a hybrid/multi-cloud environment.

This tutorial will walk you through the steps necessary to set up your Kubernetes cluster in Rancher.

How to Set up a Kubernetes Cluster with Rancher

Prerequisites

Add a Kubernetes Cluster to Rancher

1. On the home page of your Rancher graphical interface, click the Create button above the list of the available clusters.

The Clusters section in the Rancher graphical interface, with the Create button on the right.

The Cluster: Create page opens.

You can register a cluster you created before or create a new cluster using the existing nodes. This article will demonstrate the creation of a new Kubernetes cluster.

2. Click the Custom button at the bottom of the page to start the process.

Creating a new custom Kubernetes cluster in Rancher.

3. Next, provide a cluster name. In the expandable sections below, set up member roles and configure labels and annotations for the cluster:

Naming the cluster, setting up member roles and labels in Rancher.

4. Scroll down to Cluster Options and expand the Kubernetes Options section. Select the Kubernetes version and the network provider.

Managing Kubernetes options in the Cluster Options section of the Add Cluster dialogue in Rancher.

5. In the Cloud Provider subsection, select your cloud provider. Choose None if you do not wish to set up the cloud:

Choosing the cloud provider in the Cloud provider section in Rancher.

6. When you finish setting up the cluster, scroll to the bottom of the page and click the Next button.

7. Next, customize the command you will run on your existing machines. Start by selecting the roles for the node:

Customizing the node run command in Rancher.

Note: Every Kubernetes cluster needs at least one etcd node for key-value storage and one Control Plane to maintain object records.

8. Press the blue button to copy the command below and click Done.

The node run command in Rancher.

9. Execute the command on the applicable nodes. The command installs a Docker version of a Rancher agent. The following output confirms the successful download of the container:

Executing the node run command on a node.

Manage the Cluster

If the cluster successfully initiates, you should see the Cluster Dashboard similar to the image below.

The classic cluster dashboard in Rancher.

The board provides information on the state of the cluster components. The system sends alerts when components malfunction and shows the basic system parameters - CPU, memory, and pods.

Deploy a Cluster Workload in Rancher

Rancher enables you to deploy and scale Kubernetes cluster workloads easily. The following example shows you how to deploy an Nginx demo server on the cluster you created.

1. In the menu on the left side of your Cluster Dashboard, select Workload item. The Workloads section appears.

2. Select Create in the upper right corner of the screen.

Navigating to a new project in Rancher to begin deploying a workload.

3. Then, select Deployment in the Deployment: Create section.

Selecting Deployment as the object to create.

4. Give a name to the deployment, assign pods, and provide the Docker image's name and the namespace for the deployment.

5. Next, click Add Port and type in the necessary port configuration.

Defining deployment in Rancher.

6. Scroll down for more options, such as setting up environment variables, node scheduling, health checks, etc. When you finish, click Launch at the bottom of the page and wait for the workload to initiate. When the process completes, the workload displays the Active tag.

The cluster dashboard showing an active workload in Rancher.

To test the deployment, navigate in your browser to the port you assigned in Step 5. The Nginx demo page should display:

The Nginx demo server page.

Note: phoenixNAP Kubernetes Controller for BMC allows users to provision and manage BMC server instances directly from a Kubernetes cluster.

Modify a Deployment in Rancher

Rancher makes it possible to scale deployments up or down quickly. The following example shows you how to scale the number of pods of the Nginx demo server from one to three.

1. In the cluster dashboard, click the green bar in the Health column for the deployment you wish to edit. The field expands.

2. Click the + button twice to bring the number of replicas up to three.

Scaling replicas from the Deployments page.

Another way to scale replicas and edit other configuration options is explained in the steps below:

1.  In the Cluster Dashboard, click the three dots on the right side of the workload item you wish to modify. Then, choose Edit Config.

Navigating to the Edit Config section for a deployment.

The Deployment: Create page appears.

2. Change the number in the Replicas field to scale your deployment.

Editing the number of replicas in the Edit Config section.

When you finish, select Launch at the bottom of the page to apply the changes.

Note: Read our Rancher Node Driver Tutorial to learn how to work with node drivers and node templates in Rancher.

Conclusion

This tutorial showed you how to add and manage your Kubernetes cluster in Rancher. Additionally, the guide provided an example of how to create and edit cluster workloads.

Was this article helpful?
YesNo
Marko Aleksic
Marko Aleksić is a Technical Writer at phoenixNAP. His innate curiosity regarding all things IT, combined with over a decade long background in writing, teaching and working in IT-related fields, led him to technical writing, where he has an opportunity to employ his skills and make technology less daunting to everyone.
Next you should read
How to Install Rancher on Ubuntu
September 2, 2020

Rancher is a container management platform that helps manage Kubernetes at scale. It makes it simple to deploy and run Kubernetes everywhere. The software is...
Read more
How to Install Rancher on CentOS 7
September 22, 2020

Install Rancher on CentOS, a container management platform used by virtualization vendors with Kubernetes in their standard infrastructure. The software simplifies deploying...
Read more
19 Kubernetes Best Practices for Building Efficient Clusters
September 23, 2020

Use the outlined Kubernetes best practices to build optimized containers, streamline deployments...
Read more
How to Set Up and Run Kafka on Kubernetes
February 12, 2020

This tutorial shows you how to configure a Kafka server on a Kubernetes cluster. Kafka is a messaging system that collects and processes extensive amounts of data...
Read more