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.
- A Kubernetes cluster
- Rancher installed
- A Rancher-supported Docker version installed on all machines
- Sudo privileges
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 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.
3. Next, provide a cluster name. In the expandable sections below, set up member roles and configure labels and annotations for the cluster:
4. Scroll down to Cluster Options and expand the Kubernetes Options section. Select the Kubernetes version and the network provider.
5. In the Cloud Provider subsection, 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. Next, customize the command you will run on your existing machines. Start by selecting the roles for the node:
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.
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:
Manage the Cluster
If the cluster successfully initiates, you should see the Cluster Dashboard similar to the image below.
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.
3. Then, select Deployment in the Deployment: Create section.
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.
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.
To test the deployment, navigate in your browser to the port you assigned in Step 5. The Nginx demo page should display:
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.
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.
The Deployment: Create page appears.
2. Change the number in the Replicas field to scale your deployment.
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.
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.