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 hybrid/multi-cloud environment.
This tutorial will walk you through the steps necessary to set up your Kubernetes cluster in Rancher.
- Kubernetes cluster
- Rancher installed
- A Rancher-supported Docker version installed on all machines
- Sudo privileges
Add a Kubernetes Cluster to Rancher
1. Select the Clusters item in the upper menu in your Rancher graphical interface and then click the Add Cluster button.
Another page opens with available cluster types.
2. 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. Click the Existing nodes button to start the process.
3. Provide a cluster name on the next screen. In the expandable sections below, set up member roles and configure labels and annotations for the cluster:
4. Scroll down to the Cluster Options and expand the Kubernetes Options section. Select the Kubernetes version and the network provider.
5. In the Cloud Provider subsection of the Kubernetes Options, select your cloud provider. Choose None if you do not wish to set up the cloud:
6. When you finish setting up the cluster, scroll to the bottom of the page and click the Next button.
7. On the new page, customize the command to copy and run on the machines that belong to the cluster you wish to add. Select the roles for a node:
Note: Every Kubernetes cluster needs to have 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. Then execute the command on the applicable nodes.
9. The command installs a docker version of Rancher agent. The following output confirms the successful download of the container:
10. Go to the Rancher GUI and click Done at the bottom of the Cluster Options page.
Manage the Cluster
If the cluster successfully initiates, the classic Rancher cluster dashboard is displayed.
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.
Another way to monitor the cluster is to use the Cluster Explorer. To reach the tool, click the yellow button in the upper-right corner of the page in the main menu:
The Cluster Explorer offers a more compact way to monitor and manage the cluster and the deployed workloads.
Deploy a Cluster Workload in Rancher
Rancher enables you to deploy and scale Kubernetes cluster workloads easily. The following example will show you how to deploy an Nginx demo server on the cluster you created.
1. In the main menu, hover over the Global section, then the cluster name, and finally, click the Default project.
2. In the cluster dashboard, click the Deploy button.
The Deploy Workload page displays.
3. Give a name to the deployment, assign pods, provide the name of the Docker image and the namespace for the deployment. Next, click the Add Port button and type in the necessary port configuration.
4. 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 will display the Active tag.
To test the deployment, go to the port you assigned as the listening port in Step 3. The Nginx demo page displays:
Modify a Deployment in Rancher
Rancher makes it possible to scale deployments up or down quickly. The following example will show you how to scale the number of pods of the Nginx demo server from one to three.
1. In the cluster dashboard, click the three dots on the right side of the workload item you wish to modify and choose Edit.
The Edit Workload page appears.
2. Type the number you want to change the number of pods dedicated to the workload:
The page allows you to change the rest of the configuration you provided when you created the workload.
3. Click the Save button at the bottom of the page when you perform all the necessary edits.
Finally, the workload reinitiates:
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.