Skip to main content

Praktikum Kubernetes

Topologi cluster kubernetes

image.png

Repository ubuntu 20.04 lokal

deb http://kebo.pens.ac.id/ubuntu/ focal main restricted universe multiverse
deb http://kebo.pens.ac.id/ubuntu/ focal-updates main restricted universe multiverse
deb http://kebo.pens.ac.id/ubuntu/ focal-security main restricted universe multiverse
deb http://kebo.pens.ac.id/ubuntu/ focal-backports main restricted universe multiverse
deb http://kebo.pens.ac.id/ubuntu/ focal-proposed main restricted universe multiverse

Praktikum

  • Disable swap

pastikan swap sudah off (non permanen) menggunakan command

sudo swapoff -a

disable swap secara permanen penggunaan swap

image.png

  • Lakukan update konfigurasi /etc/hosts sesuai cluster ip anda di setiap server
cat <<EOF>> /etc/hosts
192.168.56.102 kubemaster
192.168.56.103 worker1
192.168.56.104 worker2
EOF

image.png

  • Update hostname sesuai fungsi masing-masing server

image.png

image.png

image.png

  • Update dan aktifkan beberapa modul sesuai kebutuhan
cat > /etc/modules-load.d/containerd.conf <<EOF
overlay
br_netfilter
EOF

modprobe overlay
modprobe br_netfilter

# Mengatur parameter sysctl yang diperlukan, dimana ini akan bernilai tetap setiap kali penjalanan ulang.
cat > /etc/sysctl.d/99-kubernetes-cri.conf <<EOF
net.bridge.bridge-nf-call-iptables  = 1
net.ipv4.ip_forward                 = 1
net.bridge.bridge-nf-call-ip6tables = 1
EOF

sysctl --system
  • Install kubadm, kubelet and kubectl

kubeadm: perintah untuk mem-bootstrap cluster.

kubelet: komponen yang berjalan pada semua mesin di cluster Anda dan melakukan hal-hal seperti memulai pod dan container.

kubectl: baris perintah yang digunakan untuk berkomunikasi dengan cluster Anda.

    1. Update paket dan library yang diperlukan dari repositori

       

      sudo apt-get update && sudo apt-get install -y apt-transport-https curl
    2. Download the public signing key untuk Kubernetes dari paket repositori

       

      curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
    3. Tambahkan appropriate Kubernetes padaapt repository
cat <<EOF | sudo tee /etc/apt/sources.list.d/kubernetes.list
deb https://apt.kubernetes.io/ kubernetes-xenial main
EOF

        4. lakukan instalasi

sudo apt-get update
sudo apt-get install -y kubelet kubeadm kubectl
sudo apt-mark hold kubelet kubeadm kubectl
  • Install runtime (Containerd)

Untuk menjalankan Container pada Pod, Kubernetes menggunakan runtime Container

Install containerd

# (Meninstal containerd)
## Mengatur repositori paket
### Install packages to allow apt to use a repository over HTTPS
apt-get update && apt-get install -y apt-transport-https ca-certificates curl software-properties-common
## Menambahkan key GPG resmi dari Docker:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
## Mengatur repositori paket Docker
add-apt-repository \
    "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
    $(lsb_release -cs) \
    stable"
## Menginstal containerd
apt-get update && apt-get install -y containerd.io
# Mengonfigure containerd
mkdir -p /etc/containerd
containerd config default | sudo tee /etc/containerd/config.toml
# Menjalankan ulang containerd
systemctl restart containerd
systemctl enable containerd
systemctl status containerd
  • Konfigurasi node master

pastikan modul br_netfilter aktif menggunakan command berikut

lsmod | grep br_netfilter

image.png

aktifkan layanan kubelet menggunakan command berikut

systemctl enable kubelet

inisialisasi control plane

root@master:/home/barkah# kubeadm init
I0110 07:36:38.348918   12801 version.go:256] remote version is much newer: v1.29.0; falling back to: stable-1.28
[init] Using Kubernetes version: v1.28.5
[preflight] Running pre-flight checks
[preflight] Pulling images required for setting up a Kubernetes cluster
[preflight] This might take a minute or two, depending on the speed of your internet connection
[preflight] You can also perform this action in beforehand using 'kubeadm config images pull'
W0110 07:38:11.519367   12801 checks.go:835] detected that the sandbox image "registry.k8s.io/pause:3.6" of the container runtime is inconsistent with that used by kubeadm. It is recommended that using "registry.k8s.io/pause:3.9" as the CRI sandbox image.
[certs] Using certificateDir folder "/etc/kubernetes/pki"
[certs] Generating "ca" certificate and key
[certs] Generating "apiserver" certificate and key
[certs] apiserver serving cert is signed for DNS names [kubernetes kubernetes.default kubernetes.default.svc kubernetes.default.svc.cluster.local master] and IPs [10.96.0.1 10.0.2.15]
[certs] Generating "apiserver-kubelet-client" certificate and key
[certs] Generating "front-proxy-ca" certificate and key
[certs] Generating "front-proxy-client" certificate and key
[certs] Generating "etcd/ca" certificate and key
[certs] Generating "etcd/server" certificate and key
[certs] etcd/server serving cert is signed for DNS names [localhost master] and IPs [10.0.2.15 127.0.0.1 ::1]
[certs] Generating "etcd/peer" certificate and key
[certs] etcd/peer serving cert is signed for DNS names [localhost master] and IPs [10.0.2.15 127.0.0.1 ::1]
[certs] Generating "etcd/healthcheck-client" certificate and key
[certs] Generating "apiserver-etcd-client" certificate and key
[certs] Generating "sa" key and public key
[kubeconfig] Using kubeconfig folder "/etc/kubernetes"
[kubeconfig] Writing "admin.conf" kubeconfig file
[kubeconfig] Writing "kubelet.conf" kubeconfig file
[kubeconfig] Writing "controller-manager.conf" kubeconfig file
[kubeconfig] Writing "scheduler.conf" kubeconfig file
[etcd] Creating static Pod manifest for local etcd in "/etc/kubernetes/manifests"
[control-plane] Using manifest folder "/etc/kubernetes/manifests"
[control-plane] Creating static Pod manifest for "kube-apiserver"
[control-plane] Creating static Pod manifest for "kube-controller-manager"
[control-plane] Creating static Pod manifest for "kube-scheduler"
[kubelet-start] Writing kubelet environment file with flags to file "/var/lib/kubelet/kubeadm-flags.env"
[kubelet-start] Writing kubelet configuration to file "/var/lib/kubelet/config.yaml"
[kubelet-start] Starting the kubelet
[wait-control-plane] Waiting for the kubelet to boot up the control plane as static Pods from directory "/etc/kubernetes/manifests". This can take up to 4m0s
[apiclient] All control plane components are healthy after 15.509326 seconds
[upload-config] Storing the configuration used in ConfigMap "kubeadm-config" in the "kube-system" Namespace
[kubelet] Creating a ConfigMap "kubelet-config" in namespace kube-system with the configuration for the kubelets in the cluster
[upload-certs] Skipping phase. Please see --upload-certs
[mark-control-plane] Marking the node master as control-plane by adding the labels: [node-role.kubernetes.io/control-plane node.kubernetes.io/exclude-from-external-load-balancers]
[mark-control-plane] Marking the node master as control-plane by adding the taints [node-role.kubernetes.io/control-plane:NoSchedule]
[bootstrap-token] Using token: 2zs2sf.mwbg4kfwo6fvgafq
[bootstrap-token] Configuring bootstrap tokens, cluster-info ConfigMap, RBAC Roles
[bootstrap-token] Configured RBAC rules to allow Node Bootstrap tokens to get nodes
[bootstrap-token] Configured RBAC rules to allow Node Bootstrap tokens to post CSRs in order for nodes to get long term certificate credentials
[bootstrap-token] Configured RBAC rules to allow the csrapprover controller automatically approve CSRs from a Node Bootstrap Token
[bootstrap-token] Configured RBAC rules to allow certificate rotation for all node client certificates in the cluster
[bootstrap-token] Creating the "cluster-info" ConfigMap in the "kube-public" namespace
[kubelet-finalize] Updating "/etc/kubernetes/kubelet.conf" to point to a rotatable kubelet client certificate and key
[addons] Applied essential addon: CoreDNS
[addons] Applied essential addon: kube-proxy

Your Kubernetes control-plane has initialized successfully!

To start using your cluster, you need to run the following as a regular user:

  mkdir -p $HOME/.kube
  sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
  sudo chown $(id -u):$(id -g) $HOME/.kube/config

Alternatively, if you are the root user, you can run:

  export KUBECONFIG=/etc/kubernetes/admin.conf

You should now deploy a pod network to the cluster.
Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:
  https://kubernetes.io/docs/concepts/cluster-administration/addons/

Then you can join any number of worker nodes by running the following on each as root:

kubeadm join 10.0.2.15:6443 --token 2zs2sf.mwbg4kfwo6fvgafq \
        --discovery-token-ca-cert-hash sha256:eaad0b4086b48fd32c2cea47f3a362adb6b7cf6f86f8323ffd14afbbf6574b00

download image menggunakan perintah kubeadm

kubeadm config images pull

image.png

cek config cluster kubernates

root@master:/home/barkah# kubectl config view
apiVersion: v1
clusters:
- cluster:
    certificate-authority-data: DATA+OMITTED
    server: https://10.0.2.15:6443
  name: kubernetes
contexts:
- context:
    cluster: kubernetes
    user: kubernetes-admin
  name: kubernetes-admin@kubernetes
current-context: kubernetes-admin@kubernetes
kind: Config
preferences: {}
users:
- name: kubernetes-admin
  user:
    client-certificate-data: DATA+OMITTED
    client-key-data: DATA+OMITTED

cek status node master

image.png

status NotReady ini perlu install network plugin terlebih dahulu

  • Install calico network plugin 
curl https://raw.githubusercontent.com/projectcalico/calico/v3.27.0/manifests/calico-etcd.yaml -o calico.yaml
kubectl apply -f calico.yaml

image.png

cek status master nodes

image.png

  • asdasd
  • sdasda

Referensi