setup k8s cluster rancher

Jump toUpdate content

Setting up a Kubernetes cluster using Rancher on Ubuntu Bionic Beaver

Published on 12 August 2019
  • Kubernetes
  • Rancher
  • k8s
  • cluster
  • container-management

Rancher Overview

Rancher is an open-source container management platform, providing an graphical interface making container management easier.

The GUI of Rancher makes it easy to manage secrets, handle roles and permissions. It allows to scale nodes and pods, set up load balancers without the requirement of a command line tool or the editing of hard to read YAML files.

Security & Identity (IAM):

You may need certain IAM permissions to carry out some actions described on this page. This means:

  • you are the Owner of the Scaleway Organization in which the actions will be carried out, or
  • you are an IAM user of the Organization, with a policy granting you the necessary permission sets

Spinning up the required Instances

  1. Log into the Scaleway console.

  2. Click Instances in the menu on the left:

  3. To deploy Instances with Docker pre-installed, click + Create an Instance:

  4. Click the InstantApps tab, and choose the Docker image:

  5. Choose the region for the Instance, the Instance type and a name for the Instance, i.e. rancher1 click Create a new Instance.

  6. Repeat these steps two more times to spin up a total of three Instances running Docker.

Installing Rancher

  1. Log into the first Instance (rancher1) via SSH.
  2. Launch the following command to fetch the docker image rancher/rancher to run in a container with automatic restarting enabled in case the container fails. Edit the value rancher.example.com with the personalized domain name pointing to the instance to generate a Lets Encrypt certificate automatically:
    docker run -d --restart=unless-stopped -p 80:80 -p 443:443 -v /host/rancher:/var/lib/rancher rancher/rancher --acme-domain rancher.example.com

Configuring Rancher

  1. Once Rancher is installed, open a web browser and point it to your rancher domain (i.e. https://rancher.example.com). The following page displays:
  2. Enter a password and its confirmation and click Continue to move forward with the installation of Rancher.1. Once Rancher is installed, open a web browser and point it to your rancher domain (i.e. https://rancher.example.com). The following page displays:
  3. Enter a password and its confirmation and click Continue to move forward with the installation of Rancher.ebp” alt="" />
  4. The (empty) Rancher Dashboard displays:

Creating a cluster

  1. Click Add Cluster to configure a new Kubernetes cluster.

  2. The cluster creation page displays. Click Custom to deploy the Cluster on the already launched Scaleway Instances.

  3. Enter a name for the cluster, choose the desired Kubernetes version and network provider and select None as cloud provider.

  4. Choose the Options for the Worker nodes. A Kubernets cluster needs to have at least one etcd and one control plane.

    • etcd is a key value storage system used by Kubernetes to keep the state of the entire enivironment. It is recommended to run an odd number of copies of the etcd for redundancy (e.g. 1, 3, 5,…).
    • The Kubernetes control plane maintains an record of all Objects (i.e. Pods) in a cluster and updates then with the configuration provided in the Rancher admin interface
    • Kubernetes workers run the actual workloads and monitoring tools to ensure the healthiness of the containers. All Pod deployments are made on worker node.

    Choose the roles for each of the Instances in the cluster and run the command shown on the page to install the required software and link them with Rancher:

    Once all Instances are ready, click Done to initialize the cluster.

  5. Once the cluster is ready, the dashboard displays:

Deploying a cluster workload

The cluster is ready now and the deployment of a first pod can take place. A Pod is the smallest and simplest execution unit of a Kubernetes application that you can create or deploy.

  1. Head over Global in the header bar, select the cluster and click Default from the drop-down menu:

  2. The clusters dashboard displays. Click Deploy:

  3. Enter the details of the workload:

    • Name: A friendly name for the workload.
    • Docker Image: Enter nginxdemos/hello to deploy a Nginx demo application.
    • Click Add Port to configure the port mapping
      • Publish the container port: Set the value to port 80
      • Protocol: Set the value to TCP
      • As a: Set the Value to NodePort
      • Listening Port: Set the value to port 30000

    Click Launch to create the workload.

  4. Once deployed, open a web browser and point it to http://<rancher.example.com>:30000/. The Nginx demo application displays:

Scaling a cluster workload

Currently the Nginx demo application lives in a single pod and is deployed only on one Instance. Rancher provides the possibility to scale your deployment to multiple pods directly from the web interface.

  1. From the cluster dashboard, click then on Edit in the pop-up menu:

  2. Edit the Workload type and set the number of scalable deployments to 3:

  3. Click Save. Rancher will now send instructions to Kubernetes to update the workload configuration and to deploy 3 pods running the Nginx demo application parallel.

  4. Access the application running on the second Instance by typing: http://<second_instance_ip>:30000/ in a web browser. The Nginx demo application displays.

    For more information about Rancher and Kubernetes refer to the official documentation.