2. Install Kubernetes

Once the infrastructure is ready, you can continue with setting up a Kubernetes cluster to install Rancher in.

The steps to set up RKE, RKE2, or K3s are shown below.

For convenience, export the IP address and port of your proxy into an environment variable and set up the HTTP_PROXY variables for your current shell on every node:

  1. export proxy_host="10.0.0.5:8888"
  2. export HTTP_PROXY=http://${proxy_host}
  3. export HTTPS_PROXY=http://${proxy_host}
  4. export NO_PROXY=127.0.0.0/8,10.0.0.0/8,cattle-system.svc,172.16.0.0/12,192.168.0.0/16
  • K3s
  • RKE2
  • RKE

First configure the HTTP proxy settings on the K3s systemd service, so that K3s’s containerd can pull images through the proxy:

  1. cat <<'EOF' | sudo tee /etc/default/k3s > /dev/null
  2. HTTP_PROXY=http://${proxy_host}
  3. HTTPS_PROXY=http://${proxy_host}
  4. NO_PROXY=127.0.0.0/8,10.0.0.0/8,cattle-system.svc,172.16.0.0/12,192.168.0.0/16,.svc,.cluster.local
  5. EOF

Rancher needs to be installed on a supported Kubernetes version. To find out which versions of Kubernetes are supported for your Rancher version, refer to the Rancher Support Matrix.

To specify the K3s (Kubernetes) version, use the INSTALL_K3S_VERSION (e.g., INSTALL_K3S_VERSION="v1.24.10+k3s1") environment variable when running the K3s installation script.

On the first node, create a new cluster:

  1. curl -sfL https://get.k3s.io | INSTALL_K3S_VERSION=<VERSION> K3S_TOKEN=<TOKEN> sh -s - server --cluster-init

And then join the other nodes:

  1. curl -sfL https://get.k3s.io | INSTALL_K3S_VERSION=<VERSION> K3S_TOKEN=<TOKEN> sh -s - server --server https://<SERVER>:6443

Where <SERVER> is the IP or valid DNS of the server and <TOKEN> is the node-token from the server found at /var/lib/rancher/k3s/server/node-token.

For more information on installing K3s see the K3s installation docs.

To have a look at your cluster run:

  1. kubectl cluster-info
  2. kubectl get pods --all-namespaces

On every node, run the RKE2 installation script. Ensure that the RKE2 version you are installing is supported by Rancher.

  1. curl -sfL https://get.rke2.io | INSTALL_RKE2_CHANNEL=v1.xx sh -

Then you have to configure the HTTP proxy settings on the RKE2 systemd service, so that RKE2’s containerd can pull images through the proxy:

  1. cat <<'EOF' | sudo tee /etc/default/rke2-server > /dev/null
  2. HTTP_PROXY=http://${proxy_host}
  3. HTTPS_PROXY=http://${proxy_host}
  4. NO_PROXY=127.0.0.0/8,10.0.0.0/8,cattle-system.svc,172.16.0.0/12,192.168.0.0/16,.svc,.cluster.local
  5. EOF

Next create the RKE2 configuration file on every node following the RKE2 High Availability documentation.

After that start and enable the rke2-server service:

  1. systemctl enable rke2-server.service
  2. systemctl start rke2-server.service

For more information on installing RKE2 see the RKE2 documentation.

To have a look at your cluster run:

  1. export KUBECONFIG=/etc/rancher/rke2/rke2.yaml
  2. alias kubectl=/var/lib/rancher/rke2/bin/kubectl
  3. kubectl cluster-info
  4. kubectl get pods --all-namespaces

First, you have to install Docker and setup the HTTP proxy on all three Linux nodes. For this perform the following steps on all three nodes.

Next configure apt to use this proxy when installing packages. If you are not using Ubuntu, you have to adapt this step accordingly:

  1. cat <<'EOF' | sudo tee /etc/apt/apt.conf.d/proxy.conf > /dev/null
  2. Acquire::http::Proxy "http://${proxy_host}/";
  3. Acquire::https::Proxy "http://${proxy_host}/";
  4. EOF

Now you can install Docker:

  1. curl -sL https://releases.rancher.com/install-docker/19.03.sh | sh

Then ensure that your current user is able to access the Docker daemon without sudo:

  1. sudo usermod -aG docker YOUR_USERNAME

And configure the Docker daemon to use the proxy to pull images:

  1. sudo mkdir -p /etc/systemd/system/docker.service.d
  2. cat <<'EOF' | sudo tee /etc/systemd/system/docker.service.d/http-proxy.conf > /dev/null
  3. [Service]
  4. Environment="HTTP_PROXY=http://${proxy_host}"
  5. Environment="HTTPS_PROXY=http://${proxy_host}"
  6. Environment="NO_PROXY=127.0.0.0/8,10.0.0.0/8,cattle-system.svc,172.16.0.0/12,192.168.0.0/16"
  7. EOF

To apply the configuration, restart the Docker daemon:

  1. sudo systemctl daemon-reload
  2. sudo systemctl restart docker

Air-gapped proxy

You can now provision node driver clusters from an air-gapped cluster configured to use a proxy for outbound connections.

In addition to setting the default rules for a proxy server, you must also add the rules shown below to provision node driver clusters from a proxied Rancher environment.

You will configure your filepath according to your setup, e.g., /etc/apt/apt.conf.d/proxy.conf:

  1. acl SSL_ports port 22
  2. acl SSL_ports port 2376
  3. acl Safe_ports port 22 # ssh
  4. acl Safe_ports port 2376 # docker port

Creating the RKE Cluster

You need several command line tools on the host where you have SSH access to the Linux nodes to create and interact with the cluster:

  1. sudo curl -fsSL -o /usr/local/bin/rke https://github.com/rancher/rke/releases/download/v1.1.4/rke_linux-amd64
  2. sudo chmod +x /usr/local/bin/rke
  1. curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
  2. chmod +x ./kubectl
  3. sudo mv ./kubectl /usr/local/bin/kubectl

Next, create a YAML file that describes the RKE cluster. Ensure that the IP addresses of the nodes and the SSH username are correct. For more information on the cluster YAML, have a look at the RKE documentation.

  1. nodes:
  2. - address: 10.0.1.200
  3. user: ubuntu
  4. role: [controlplane,worker,etcd]
  5. - address: 10.0.1.201
  6. user: ubuntu
  7. role: [controlplane,worker,etcd]
  8. - address: 10.0.1.202
  9. user: ubuntu
  10. role: [controlplane,worker,etcd]
  11. services:
  12. etcd:
  13. backup_config:
  14. interval_hours: 12
  15. retention: 6

After that, you can create the Kubernetes cluster by running:

  1. rke up --config rancher-cluster.yaml

RKE creates a state file called rancher-cluster.rkestate, this is needed if you want to perform updates, modify your cluster configuration or restore it from a backup. It also creates a kube_config_cluster.yaml file, that you can use to connect to the remote Kubernetes cluster locally with tools like kubectl or Helm. Make sure to save all of these files in a secure location, for example by putting them into a version control system.

To have a look at your cluster run:

  1. export KUBECONFIG=kube_config_cluster.yaml
  2. kubectl cluster-info
  3. kubectl get pods --all-namespaces

You can also verify that your external load balancer works, and the DNS entry is set up correctly. If you send a request to either, you should receive HTTP 404 response from the ingress controller:

  1. $ curl 10.0.1.100
  2. default backend - 404
  3. $ curl rancher.example.com
  4. default backend - 404

Save Your Files

2. Install Kubernetes - 图1Important:

The files mentioned below are needed to maintain, troubleshoot and upgrade your cluster.

Save a copy of the following files in a secure location:

  • rancher-cluster.yml: The RKE cluster configuration file.
  • kube_config_cluster.yml: The Kubeconfig file for the cluster, this file contains credentials for full access to the cluster.
  • rancher-cluster.rkestate: The Kubernetes Cluster State file, this file contains the current state of the cluster including the RKE configuration and the certificates.

2. Install Kubernetes - 图2note

The “rancher-cluster” parts of the two latter file names are dependent on how you name the RKE cluster configuration file.

Issues or errors?

See the Troubleshooting page.

Next: Install Rancher