K3s adalah distribusi Kubernetes yang ringan dan mudah digunakan, ideal untuk lingkungan dengan sumber daya terbatas. Berikut adalah langkah-langkah untuk menginstalnya di Ubuntu 22.04:
Check informasi System Operasi
admin@labs-wachid:~# cat /etc/*ease DISTRIB_ID=Ubuntu DISTRIB_RELEASE=22.04 DISTRIB_CODENAME=jammy DISTRIB_DESCRIPTION="Ubuntu 22.04.4 LTS" PRETTY_NAME="Ubuntu 22.04.4 LTS" NAME="Ubuntu" VERSION_ID="22.04" VERSION="22.04.4 LTS (Jammy Jellyfish)" VERSION_CODENAME=jammy ID=ubuntu ID_LIKE=debian HOME_URL="https://www.ubuntu.com/" SUPPORT_URL="https://help.ubuntu.com/" BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/" PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy" UBUNTU_CODENAME=jammy admin@labs-wachid:~#
Install curl
sudo apt install curl -y
admin@labs-wachid:~# sudo apt install curl -y Reading package lists... Done Building dependency tree... Done Reading state information... Done curl is already the newest version (7.81.0-1ubuntu1.16). curl set to manually installed. 0 upgraded, 0 newly installed, 0 to remove and 1 not upgraded. root@labs-wachid:~#
Instalasi Helm
sudo curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 sudo chmod 700 get_helm.sh sudo ./get_helm.sh
admin@labs-wachid:~# sudo curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 root@labs-wachid:~# ls -l total 16 -rw-r--r-- 1 root root 11694 Aug 29 09:16 get_helm.sh drwx------ 3 root root 4096 Jun 20 2023 snap admin@labs-wachid:~# admin@labs-wachid:~# sudo chmod 700 get_helm.sh admin@labs-wachid:~# admin@labs-wachid:~# sudo ./get_helm.sh Downloading https://get.helm.sh/helm-v3.15.4-linux-amd64.tar.gz Verifying checksum... Done. Preparing to install helm into /usr/local/bin helm installed into /usr/local/bin/helm admin@labs-wachid:~# admin@labs-wachid:~#
Check version
helm version
root@labs-wachid:~# helm version version.BuildInfo{Version:"v3.15.4", GitCommit:"fa9efb07d9d8debbb4306d72af76a383895aa8c4", GitTreeState:"clean", GoVersion:"go1.22.6"} root@labs-wachid:~#
Melakukan instalasi K3s
Untuk mengecek versi k3s : https://github.com/k3s-io/k3s/releases
Jika akan menggunakan rancher, sebaiknya melihat kompatibility matrik dari rancher :
Master 1
echo "10.20.30.155 k3s-node-01" >> /etc/hosts echo "10.20.30.156 k3s-node-02" >> /etc/hosts curl -sfL https://get.k3s.io | INSTALL_K3S_VERSION=v1.27.11+k3s1 K3S_TOKEN=NomerTokenAndaBebas sh -s - server --cluster-init
Master 2
echo "10.20.30.155 k3s-node-01" >> /etc/hosts echo "10.20.30.156 k3s-node-02" >> /etc/hosts curl -sfL https://get.k3s.io | INSTALL_K3S_VERSION=v1.27.11+k3s1 K3S_TOKEN=NomerTokenAndaBebas sh -s - server --server https://k3s-node-01:6443
Setting kubectl
sudo mkdir ~/.kube sudo kubectl config view --raw > ~/.kube/config sudo chmod o-r ~/.kube/config sudo chmod g-r ~/.kube/config
root@labs-wachid:~# sudo mkdir ~/.kube root@labs-wachid:~# sudo kubectl config view --raw > ~/.kube/config root@labs-wachid:~# root@labs-wachid:~# sudo chmod o-r ~/.kube/config root@labs-wachid:~# sudo chmod g-r ~/.kube/config root@labs-wachid:~#
Menambahkan helm repository
sudo helm repo add rancher-latest https://releases.rancher.com/server-charts/latest sudo helm repo add jetstack https://charts.jetstack.io sudo helm repo update
root@labs-wachid:~# sudo helm repo add rancher-latest https://releases.rancher.com/server-charts/latest "rancher-latest" has been added to your repositories root@labs-wachid:~# sudo helm repo add jetstack https://charts.jetstack.io "jetstack" has been added to your repositories root@labs-wachid:~# sudo helm repo update Hang tight while we grab the latest from your chart repositories... ...Successfully got an update from the "jetstack" chart repository ...Successfully got an update from the "rancher-latest" chart repository Update Complete. ⎈Happy Helming!⎈ root@labs-wachid:~#
Install cert manager
kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.15.1/cert-manager.crds.yaml
root@labs-wachid:~# kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.15.1/cert-manager.crds.yaml customresourcedefinition.apiextensions.k8s.io/certificaterequests.cert-manager.io created customresourcedefinition.apiextensions.k8s.io/certificates.cert-manager.io created customresourcedefinition.apiextensions.k8s.io/challenges.acme.cert-manager.io created customresourcedefinition.apiextensions.k8s.io/clusterissuers.cert-manager.io created customresourcedefinition.apiextensions.k8s.io/issuers.cert-manager.io created customresourcedefinition.apiextensions.k8s.io/orders.acme.cert-manager.io created root@labs-wachid:~#
helm install cert-manager jetstack/cert-manager --namespace cert-manager --create-namespace
root@labs-wachid:~# helm install cert-manager jetstack/cert-manager --namespace cert-manager --create-namespace NAME: cert-manager LAST DEPLOYED: Thu Aug 29 09:44:44 2024 NAMESPACE: cert-manager STATUS: deployed REVISION: 1 TEST SUITE: None NOTES: cert-manager v1.15.3 has been deployed successfully! In order to begin issuing certificates, you will need to set up a ClusterIssuer or Issuer resource (for example, by creating a 'letsencrypt-staging' issuer). More information on the different types of issuers and how to configure them can be found in our documentation: https://cert-manager.io/docs/configuration/ For information on how to configure cert-manager to automatically provision Certificates for Ingress resources, take a look at the `ingress-shim` documentation: https://cert-manager.io/docs/usage/ingress/ root@labs-wachid:~#
Install Rancher
Jika belum mempunyai domain, bisa menggunakan domain *.sslip.io domain ini akan meresolve dalam ip, contoh jika kita membuat 10.20.30.155.sslip.io ketika di ping akan reply ip 10.20.30.155
helm install rancher rancher-latest/rancher --namespace cattle-system --set hostname=10.20.30.155.sslip.io --set replicas=3 --set bootstrapPassword=P455w0rdRancher --create-namespace
root@labs-wachid:~# helm install rancher rancher-latest/rancher --namespace cattle-system --set hostname=10.20.30.155.sslip.io --set replicas=3 --set bootstrapPassword=P455w0rdRancher --create-namespace NAME: rancher LAST DEPLOYED: Thu Aug 29 10:08:36 2024 NAMESPACE: cattle-system STATUS: deployed REVISION: 1 TEST SUITE: None NOTES: Rancher Server has been installed. NOTE: Rancher may take several minutes to fully initialize. Please standby while Certificates are being issued, Containers are started and the Ingress rule comes up. Check out our docs at https://rancher.com/docs/ If you provided your own bootstrap password during installation, browse to https://10.20.30.155.sslip.io to get started. If this is the first time you installed Rancher, get started by running this command and clicking the URL it generates: ``` echo https://103.67.78.224.sslip.io/dashboard/?setup=$(kubectl get secret --namespace cattle-system bootstrap-secret -o go-template='{{.data.bootstrapPassword|base64decode}}') ``` To get just the bootstrap password on its own, run: ``` kubectl get secret --namespace cattle-system bootstrap-secret -o go-template='{{.data.bootstrapPassword|base64decode}}{{ "\n" }}' ``` Happy Containering! root@labs-wachid:~#
Check Password Rancher
echo https://10.20.30.155.sslip.io/dashboard/?setup=$(kubectl get secret --namespace cattle-system bootstrap-secret -o go-template='{{.data.bootstrapPassword|base64decode}}')
root@labs-wachid:~# kubectl get secret --namespace cattle-system bootstrap-secret -o go-template='{{.data.bootstrapPassword|base64decode}}{{ "\n" }}' P455w0rdRancher root@labs-wachid:~#
Check status deployment
kubectl -n cattle-system rollout status deploy/rancher
root@k3s-node-01:~# kubectl -n cattle-system rollout status deploy/rancher deployment "rancher" successfully rolled out root@k3s-node-01:~#
Masuk ke GUI rancher