ON THIS PAGE
Create a Rancher RKE2 Cluster
SUMMARY See examples on how to create a Rancher RKE2 cluster.
Use this example procedure to create a Rancher RKE2 cluster.
This procedure configures a server node and two agent nodes. In Rancher, a server node functions as a control plane node, and an agent node functions as a worker node. Tailor this procedure to the number of nodes in your cluster.
We provide this example procedure purely for informational purposes.
For more information about creating an RKE2 cluster, see the official Rancher documentation: https://docs.rke2.io/install/quickstart.
Before you start, make sure you've brought up the servers or VMs that you plan to use for the cluster nodes.
The command line examples below don't always show absolute directory paths. We leave it to you to apply these commands within your directory structure.
Configure a Server Node
Use this procedure to configure a server node.
A server node functions as a control plane node in RKE2. The server node used in our single cluster example is an Ubuntu host reachable at IP address 172.16.0.11.
- From your local computer, SSH into the server node as the root user.
-
Create a
config.yaml
file at/etc/rancher/rke2
with the following content.cni: - none
-
Install, enable, and start the
rke2-server
service.-
Download the RKE2 installation script:
curl -sfL https://get.rke2.io -o install.sh
-
Make the installation script executable.
chmod +x install.sh
-
Set the installation variables to point to the desired
release.
INSTALL_RKE2_CHANNEL=latest
INSTALL_RKE2_CHANNEL_URL=https://github.com/rancher/rke2/releases
-
Run the installation script.
./install.sh
This script installs therke2-server
service. -
Enable and start the
rke2-server
service.systemctl enable rke2-server.service
systemctl start rke2-server.service
-
Verify the status of the
rke2-server
service.systemctl status rke2-server
● rke2-server.service - Rancher Kubernetes Engine v2 (server) Loaded: loaded (/usr/local/lib/systemd/system/rke2-server.service; enabled; vendor preset: enabled) Active: active (running) since Tue 2023-06-06 17:37:38 UTC; 1 day 22h ago
-
Download the RKE2 installation script:
-
Copy the kubeconfig file into the default kubeconfig directory.
mkdir ~/.kube
cp /etc/rancher/rke2/rke2.yaml ~/.kube/config
-
Copy kubectl into your default path. For convenience, Rancher provides the
kubectl binary at the location shown.
cp /var/lib/rancher/rke2/bin/kubectl /usr/local/bin
-
Show the status of the pods.
kubectl get pods -A -o wide
NAMESPACE NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES kube-system cloud-controller-manager-rke2-s1 1/1 Running 0 11m 172.16.0.11 rke2-s1 <none> <none> kube-system etcd-rke2-s1 1/1 Running 0 11m 172.16.0.11 rke2-s1 <none> <none> kube-system helm-install-rke2-coredns-trcjf 0/1 Completed 0 10m 172.16.0.11 rke2-s1 <none> <none> kube-system helm-install-rke2-ingress-nginx-jghfq 0/1 Pending 0 10m <none> <none> <none> <none> kube-system helm-install-rke2-metrics-server-nvcp6 0/1 Pending 0 10m <none> <none> <none> <none> kube-system helm-install-rke2-snapshot-controller-9gbf7 0/1 Pending 0 10m <none> <none> <none> <none> kube-system helm-install-rke2-snapshot-controller-crd-l5wnn 0/1 Pending 0 10m <none> <none> <none> <none> kube-system helm-install-rke2-snapshot-validation-webhook-kqmnp 0/1 Pending 0 10m <none> <none> <none> <none> kube-system kube-apiserver-rke2-s1 1/1 Running 0 11m 172.16.0.11 rke2-s1 <none> <none> kube-system kube-controller-manager-rke2-s1 1/1 Running 0 11m 172.16.0.11 rke2-s1 <none> <none> kube-system kube-proxy-rke2-s1 1/1 Running 0 11m 172.16.0.11 rke2-s1 <none> <none> kube-system kube-scheduler-rke2-s1 1/1 Running 0 11m 172.16.0.11 rke2-s1 <none> <none> kube-system rke2-coredns-rke2-coredns-6b9548f79f-snzl4 0/1 Pending 0 10m <none> <none> <none> <none> kube-system rke2-coredns-rke2-coredns-autoscaler-57647bc7cf-dc2gx 0/1 Pending 0 10m <none> <none> <none> <none>
Some pods are not running because CN2 is not yet installed. -
Download and install the CNI plugin.
-
Create the following directory for the CNI plugin.
mkdir -p /opt/cni/bin
-
Download the CNI plugin.
cd /opt/cni/bin/
wget 'https://github.com/containernetworking/plugins/releases/download/v1.1.1/cni-plugins-linux-amd64-v1.1.1.tgz'
-
Untar and gunzip the .tgz file.
tar -xzvf cni-plugins-linux-amd64-v1.1.1.tgz
-
Create the following directory for the CNI plugin.
Configure an Agent Node
Use this procedure to configure an agent node.
An agent node functions as a worker node in RKE2. The agent nodes used in our single cluster example are Ubuntu hosts reachable at IP addresses 172.16.0.12 and 172.16.0.13.
Repeat these steps for the desired amount of agent nodes.
- SSH into the agent node as the root user.
-
Create a
config.yaml
file in the/etc/rancher/rke2
directory with the following content:server: https://<server_node_IP>:9345 token: <server_node_token>
Theserver_node_IP
is the IP address of the server (control plane) node.Theserver_node_token
is the token found in/var/lib/rancher/rke2/server/node-token
on the server node. -
Install, enable, and start the
rke2-agent
service.-
Download the RKE2 installation script:
curl -sfL https://get.rke2.io -o install.sh
-
Make the installation script executable.
chmod +x install.sh
-
Set the installation type.
INSTALL_RKE2_TYPE="agent"
-
Run the installation script.
./install.sh
This script installs therke2-agent
service.
-
Enable and start the
rke2-agent
service.systemctl enable rke2-agent.service
systemctl start rke2-agent.service
-
Verify the status of the
rke2-agent
service.systemctl status rke2-agent
● rke2-agent.service - Rancher Kubernetes Engine v2 (agent) Loaded: loaded (/usr/local/lib/systemd/system/rke2-agent.service; enabled; vendor preset: enabled) Active: active (running) since Mon 2023-06-12 17:36:21 UTC; 3min 6s ago
-
Download the RKE2 installation script:
-
Show the status of the pods.
Here's an example of the output when one agent node is up. Remember to issue this command from the server node.
kubectl get pods -A -o wide
NAMESPACE NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES kube-system cloud-controller-manager-rke2-s1 1/1 Running 0 21m 172.16.0.11 rke2-s1 <none> <none> kube-system etcd-rke2-s1 1/1 Running 0 21m 172.16.0.11 rke2-s1 <none> <none> kube-system helm-install-rke2-coredns-trcjf 0/1 Completed 0 20m 172.16.0.11 rke2-s1 <none> <none> kube-system helm-install-rke2-ingress-nginx-jghfq 0/1 Pending 0 20m <none> <none> <none> <none> kube-system helm-install-rke2-metrics-server-nvcp6 0/1 Pending 0 20m <none> <none> <none> <none> kube-system helm-install-rke2-snapshot-controller-9gbf7 0/1 Pending 0 20m <none> <none> <none> <none> kube-system helm-install-rke2-snapshot-controller-crd-l5wnn 0/1 Pending 0 20m <none> <none> <none> <none> kube-system helm-install-rke2-snapshot-validation-webhook-kqmnp 0/1 Pending 0 20m <none> <none> <none> <none> kube-system kube-apiserver-rke2-s1 1/1 Running 0 21m 172.16.0.11 rke2-s1 <none> <none> kube-system kube-controller-manager-rke2-s1 1/1 Running 0 21m 172.16.0.11 rke2-s1 <none> <none> kube-system kube-proxy-rke2-a1 1/1 Running 0 10m 172.16.0.12 rke2-a1 <none> <none> kube-system kube-proxy-rke2-s1 1/1 Running 0 21m 172.16.0.11 rke2-s1 <none> <none> kube-system kube-scheduler-rke2-s1 1/1 Running 0 21m 172.16.0.11 rke2-s1 <none> <none> kube-system rke2-coredns-rke2-coredns-6b9548f79f-snzl4 0/1 Pending 0 20m <none> <none> <none> <none> kube-system rke2-coredns-rke2-coredns-autoscaler-57647bc7cf-dc2gx 0/1 Pending 0 20m <none> <none> <none> <none>
-
Download and install the CNI plugin.
-
Create the following directory for the CNI plugin.
mkdir -p /opt/cni/bin
-
Download the CNI plugin.
cd /opt/cni/bin/
wget 'https://github.com/containernetworking/plugins/releases/download/v1.1.1/cni-plugins-linux-amd64-v1.1.1.tgz'
-
Untar and gunzip the .tgz file.
tar -xzvf cni-plugins-linux-amd64-v1.1.1.tgz
-
Create the following directory for the CNI plugin.