Hi gengz, ketemu lagi nih, saat ini kita bakal coba coba yuk buat install RKE(Rancher Kubernetes Enginer) di AWS.
Sebelumnya kalo mau baca baca apa yang cukup crucial terkait konfigurasi di AWS, bisa baca link berikut
https://rancher.com/blog/2018/2018-05-14-rke-on-aws/
https://rancher.com/docs/rke/latest/en/config-options/cloud-providers/aws/
Untuk mempermudah instalasi di EC2, kita akan pakai repo yang sudah saya buat dibawah ini
https://github.com/ludesdeveloper/terraform_ansible_kubernetes_aws_cloud_provider
Pertama yang akan kita lakukan adalah cloning dulu ya reponya, asumsi saya ansible dan terraform sudah terinstall ya

git clone https://github.com/ludesdeveloper/terraform_ansible_kubernetes_aws_cloud_provider

cd terraform_ansible_kubernetes_aws_cloud_provider

cd scripts
Nah sekarang kita akan membuat 3 instance di EC2 dengan terraform, silahkan diikuti ya
./1-terraform-execute.sh
Do you want to re-initiate terraform.tfvars file? Please type "yes" or "no"
yes
Please input access_key :
your_aws_access_key
Please input secret_key :
your_aws_secret_key
Please input cluster_name :
dev-rancher
Do you want to re-generate keypair? Please type "yes" or "no"
yes
Generating public/private rsa key pair.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in kubernetes-keypair.
Your public key has been saved in kubernetes-keypair.pub.
The key fingerprint is:
Kita akan tunggu sebentar, terraform akan melakukan inisialisasi

Setelah itu kita akan menunggu juga untuk terraform membuat infrastructure sampai selesai

Waw mantafs, sudah selsai ya gengz, yuk kita install docker dulu
cd ..
cd ansible
ansible-playbook -i hosts kube-dependencies.yml

Kita testing connect dulu ya gengz, yuk

cd ..
cd scripts
./connect-nodes.sh
master
Pastikan dokcernya jalan, saya hanya mencoba master, temen2 sekalian kalau mau coba workernya juga boleh

docker ps -a
Mantap, dockernya sudah jalan, yuk kita ke RKE, jangan lupa exit dulu ya dari ssh nya

cd ..
mkdir rke
cd rke
Untuk installasi RKE di pc temen temen, boleh baca disini ya untuk semua OS nya
https://rancher.com/docs/rke/latest/en/installation/
Saya akan lanjut menggunakan brew (MacOS)

brew install rke
Saya coba pastikan dulu rke nya sudah ada ya

which rke
rke --version
Mangstap, sudah ready nih, yuk kita buat filenya dulu
rke config --name cluster.yml
Silahkan diisi, dan disesuaikan ya gengz. Saya akan menggunakan keypair yang kita generate seperti dibawah ini
[+] Cluster Level SSH Private Key Path [~/.ssh/id_rsa]: ../terraform/kubernetes-keypair
Total host yang sudah disiapkan adalah 3, mari kita isi 3
[+] Number of Hosts [1]: 3
Untuk ssh kita bisa buka 1 tab lagi di terminal, dan masuk ke folder terraform untuk mendapatkannya

Kita bisa isi dulu untuk master
SSH Address of host (1) [none]: isi_master_ip_address
Silahkan diikuti seperti dibawah
[+] SSH Port of host (1) [22]:
[+] SSH Private Key Path of host (3.82.32.190) [none]:
[-] You have entered empty SSH key path, trying fetch from SSH key parameter
[+] SSH Private Key of host (3.82.32.190) [none]:
[-] You have entered empty SSH key, defaulting to cluster level SSH key: ../terraform/kubernetes-keypair
[+] SSH User of host (3.82.32.190) [ubuntu]:
Untuk node master kita akan pilih control plane dan juga etcd
[+] Is host (3.82.32.190) a Control Plane host (y/n)? [y]: y
[+] Is host (3.82.32.190) a Worker host (y/n)? [n]: n
[+] Is host (3.82.32.190) an etcd host (y/n)? [n]: y
Lalu lanjutkan sampai konfigurasi master selesai
[+] Override Hostname of host (3.82.32.190) [none]:
[+] Internal IP of host (3.82.32.190) [none]:
[+] Docker socket path on host (3.82.32.190) [/var/run/docker.sock]:
Selanjutnya kita akan mengconfigurasi 2 node worker dengan configurasi yang sama, kecuali pada saat pemilihan role, silahkan pilih seperti dibawah
[+] Is host (107.23.235.110) a Control Plane host (y/n)? [y]: n
[+] Is host (107.23.235.110) a Worker host (y/n)? [n]: y
[+] Is host (107.23.235.110) an etcd host (y/n)? [n]: n
Setelah itu kita akan melakukan configurasi network, saya memilih calico
Network Plugin Type (flannel, calico, weave, canal, aci) [canal]: calico
Selanjutnya kita bisa enter sampai habis
[+] Authentication Strategy [x509]:
[+] Authorization Mode (rbac, none) [rbac]:
[+] Kubernetes Docker image [rancher/hyperkube:v1.21.5-rancher1]:
[+] Cluster domain [cluster.local]:
[+] Service Cluster IP Range [10.43.0.0/16]:
[+] Enable PodSecurityPolicy [n]:
[+] Cluster Network CIDR [10.42.0.0/16]:
[+] Cluster DNS Service IP [10.43.0.10]:
[+] Add addon manifest URLs or YAML files [no]:
Setelah selesai kita akan mendapatkan file cluster.yml

Ada beberapa yang harus kita edit dulu, yuk kita vim dulu. Kita akan rubah cluster_name menjadi “kubernetes” dan cloud_provider menjadi “aws”

Silahkan di save, lalu kita jalankan perintah “rke up” di folder yang sama. RKE akan otomatis membaca cluster.yml yang telah kita buat

rke up
Berikut ini akan kita lihat jika sudah selesai ya gengz

Saat RKE berhasil terinstall, akan ada 3 file seperti dibawah ini. cluster.rkestate adalah state terakhir yang berhasil diinstall. cluster.yml adalah konfigurasi awal yang kita install terhadap cluster (kita bisa merubah di cluster.yaml lalu melakukan rke up, setelah selesai state akan di simpan kembali di cluster.rkestate. Dan yang paling terakhir kube_config_cluster.yaml adalah kubeconfig kita

Kita coba dulu ya kubeconfig nya

Selamat ya, RKE sudah siap digoyang kumendan. Untuk testing saya tambahkan file yaml dibawah ini.
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx
labels:
app: nginx
spec:
replicas: 1
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: nginx
spec:
type: LoadBalancer
selector:
app: nginx
ports:
- protocol: TCP
port: 80
targetPort: 80
Jika berhasil di apply, maka akan otomatis muncul Load Balancernya.
Untuk pengetesan lebih lanjut bisa dibaca disini ya
https://github.com/ludesdeveloper/terraform_ansible_kubernetes_aws_cloud_provider
Semoga bermanfaat
Tinggalkan Balasan