{"id":33130,"date":"2023-04-02T13:32:13","date_gmt":"2023-04-02T13:32:13","guid":{"rendered":"https:\/\/www.devopsschool.com\/blog\/?p=33130"},"modified":"2023-04-02T13:32:15","modified_gmt":"2023-04-02T13:32:15","slug":"step-by-step-to-setup-rancher-rke2-ha-cluster-using-nginx","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/step-by-step-to-setup-rancher-rke2-ha-cluster-using-nginx\/","title":{"rendered":"Step by Step to Setup Rancher RKE2 HA cluster using Nginx"},"content":{"rendered":"\n<p>I can provide you with a step-by-step guide on how to set up a Rancher RKE2 HA cluster using Nginx as the load balancer. Here are the steps:<\/p>\n\n\n\n<p><strong>Prerequisites:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Three or more Ubuntu 20.04 servers with 2 CPUs, 4GB of RAM, and 30GB of storage each<\/li>\n\n\n\n<li>Root access to all servers<\/li>\n\n\n\n<li>An SSH key pair for authentication<\/li>\n\n\n\n<li>A domain name pointing to the IP address of the load balancer<\/li>\n<\/ul>\n\n\n\n<p><strong>Step 1: Install and configure Nginx<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Log in to the server that will be used as the load balancer.<\/li>\n\n\n\n<li>Install Nginx using the following command: <code>sudo apt-get install nginx<\/code><\/li>\n\n\n\n<li>Once Nginx is installed, stop the service using the following command: <code>sudo systemctl stop nginx<\/code><\/li>\n\n\n\n<li>Open the Nginx configuration file <code>\/etc\/nginx\/nginx.conf<\/code> using your favorite text editor.<\/li>\n\n\n\n<li>Add the following content to the end of the <code>http<\/code> block to configure the load balancer:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-preformatted\">cssCopy code<code>upstream rke2_servers {\n    server &lt;IP_ADDRESS_OF_SERVER_1&gt;:6443;\n    server &lt;IP_ADDRESS_OF_SERVER_2&gt;:6443;\n    server &lt;IP_ADDRESS_OF_SERVER_3&gt;:6443;\n}\n\nserver {\n    listen 80;\n    server_name &lt;YOUR_DOMAIN_NAME&gt;;\n\n    location \/ {\n        proxy_pass https:\/\/rke2_servers;\n        proxy_set_header Host $host;\n        proxy_set_header X-Real-IP $remote_addr;\n    }\n}\n<\/code><\/pre>\n\n\n\n<ol class=\"wp-block-list\" start=\"6\">\n<li>Save and close the configuration file.<\/li>\n\n\n\n<li>Start the Nginx service using the following command: <code>sudo systemctl start nginx<\/code><\/li>\n<\/ol>\n\n\n\n<p><strong>Step 2: Install RKE2 on all servers<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Log in to all servers as the root user.<\/li>\n\n\n\n<li>Download the RKE2 binary using the following command: <code>curl -sfL https:\/\/get.rke2.io | sh -s -- --version v1.21.4+rke2r1<\/code><\/li>\n\n\n\n<li>Once the binary is downloaded, install RKE2 using the following command: <code>sudo installer -o root -g root -m 0755 -n \/usr\/local\/bin\/rke2 \/tmp\/rke2*\/rke2<\/code><\/li>\n\n\n\n<li>Initialize RKE2 using the following command: <code>sudo rke2 server --cluster-init<\/code><\/li>\n\n\n\n<li>Once the initialization is complete, copy the <code>kubeconfig.yaml<\/code> file to your local machine using the following command: <code>sudo cat \/etc\/rancher\/rke2\/rke2.yaml &gt; kubeconfig.yaml<\/code><\/li>\n\n\n\n<li>Repeat steps 2-5 for all servers in the cluster.<\/li>\n<\/ol>\n\n\n\n<p><strong>Step 3: Configure the Kubernetes API server<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Open the <code>kubeconfig.yaml<\/code> file using your favorite text editor.<\/li>\n\n\n\n<li>Find the <code>server<\/code> entry and replace the IP address with the domain name of the load balancer.<\/li>\n\n\n\n<li>Save and close the file.<\/li>\n<\/ol>\n\n\n\n<p><strong>Step 4: Join the cluster<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Log in to each server as the root user.<\/li>\n\n\n\n<li>Run the following command to join the cluster: <code>sudo rke2 server --server https:\/\/&lt;YOUR_DOMAIN_NAME&gt;:6443 --token &lt;CLUSTER_TOKEN&gt;<\/code><\/li>\n\n\n\n<li>Repeat step 2 for all servers in the cluster.<\/li>\n<\/ol>\n\n\n\n<p><strong>Step 5: Verify the cluster<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Log in to any server as the root user.<\/li>\n\n\n\n<li>Verify the status of the cluster using the following command: <code>sudo kubectl get nodes<\/code><\/li>\n\n\n\n<li>If all nodes are in the <code>Ready<\/code> state, the cluster is successfully set up.<\/li>\n<\/ol>\n\n\n\n<p>That&#8217;s it! You have successfully set up a Rancher RKE2 HA cluster using Nginx as the load balancer.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I can provide you with a step-by-step guide on how to set up a Rancher RKE2 HA cluster using Nginx as the load balancer. Here are the steps: Prerequisites: Step 1: Install and configure Nginx cssCopy codeupstream rke2_servers { server &lt;IP_ADDRESS_OF_SERVER_1&gt;:6443; server &lt;IP_ADDRESS_OF_SERVER_2&gt;:6443; server &lt;IP_ADDRESS_OF_SERVER_3&gt;:6443; } server { listen 80; server_name &lt;YOUR_DOMAIN_NAME&gt;; location \/ {&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"_kad_post_classname":"","_joinchat":[],"footnotes":""},"categories":[2],"tags":[],"class_list":["post-33130","post","type-post","status-publish","format-standard","hentry","category-uncategorised"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/33130","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=33130"}],"version-history":[{"count":1,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/33130\/revisions"}],"predecessor-version":[{"id":33131,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/33130\/revisions\/33131"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=33130"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=33130"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=33130"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}