Skip to content

Instantly share code, notes, and snippets.

@gilangvperdana
Last active November 14, 2022 13:06
Show Gist options
  • Save gilangvperdana/5c671145e474a8a20dd85c5b05e067bf to your computer and use it in GitHub Desktop.
Save gilangvperdana/5c671145e474a8a20dd85c5b05e067bf to your computer and use it in GitHub Desktop.
Setup RKE Cluster on Ubuntu 20.04LTS

Brief

RKE a.k.a Rancher Kubernetes Engine are Kubernetes Deployer by Rancher. Now we will create RKE cluster on Ubuntu 20.04 LTS

Environment

  • 2x Ubuntu 20.04LTS
  • 16GB RAM
  • 50GB Storage
  • 4VCPU

Deployment

  • Declare Hosts on each node of cluster (All nodes)
nano /etc/hosts

---
192.168.3.151 node1
192.168.3.152 node2
  • Declare each node of cluster pubkey to all nodes (All nodes)
ssh-keygen
ssh-copy-id node2
ssh-copy-id node1
  • Install docker on each node of cluster
apt update -y && apt-get full-upgrade -y
sudo apt-get update && sudo apt-get install apt-transport-https ca-certificates curl software-properties-common -y
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" 
sudo apt-get update && sudo apt-get install docker-ce containerd.io -y
sudo groupadd docker
sudo usermod -aG docker $USER
newgrp docker
  • Download RKE Binary

    mkdir rke
    wget https://github.com/rancher/rke/releases/download/v1.4.0/rke_linux-amd64
    mv rke_linux-amd64 rke
    chmod +x rke
    
  • Grant tcp & root ssh user

nano /etc/ssh/sshd_config

---
AllowTcpForwarding yes
PermitRootLogin yes

systemctl restart sshd
  • Deploy with rke command
# Make sure `cluster.yml` on same directory on `rke` binnary.
./rke up
  • Create cluster.yml
nodes:
    - address: 192.168.3.151
      user: root
      role: [controlplane, etcd, worker]
      hostname_override: node1
    - address: 192.168.3.152
      user: root
      role: [controlplane, etcd, worker]
      hostname_override: node2
ingress:
  provider: nginx
  options:
    use-forwarded-headers: "true"
  • Install Kubectl
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
curl -LO "https://dl.k8s.io/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl.sha256"
echo "$(cat kubectl.sha256)  kubectl" | sha256sum --check
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
chmod +x kubectl
mkdir -p ~/.local/bin
mv ./kubectl ~/.local/bin/kubectl
kubectl version --client
  • Create Kubeconfig
mkdir /root/.kube
cp /root/rke/kube_config_cluster.yml /root/.kube/config
  • Verify
kubectl get nodes

Cleanup Cluster

nano cleanup.sh
docker rm -f $(docker ps -qa)
docker rmi -f $(docker images -q)
docker volume rm $(docker volume ls -q)

for mount in $(mount | grep tmpfs | grep '/var/lib/kubelet' | awk '{ print $3 }') /var/lib/kubelet /var/lib/rancher; do umount $mount; done


rm -rf /etc/ceph \
       /etc/cni \
       /etc/kubernetes \
       /opt/cni \
       /opt/rke \
       /run/secrets/kubernetes.io \
       /run/calico \
       /run/flannel \
       /var/lib/calico \
       /var/lib/etcd \
       /var/lib/cni \
       /var/lib/kubelet \
       /var/lib/rancher/rke/log \
       /var/log/containers \
       /var/log/kube-audit \
       /var/log/pods \
       /var/run/calico


sudo reboot
chmod +x cleanup.sh
./cleanup.sh

Alternative Kubernetes Deployer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment