Kubernetes adalah sistem orkestrasi container open-source untuk mengotomatisasi penerapan, penskalaan, dan pengelolaan aplikasi komputer.
Sebelum memulai, pastikan perangkat lunak Anda mutakhir
sudo apt apdate
sudo apt upgrade
Instal
Instal paket berikut di semua mesin Anda:
kubeadm
:perintah untuk mem-bootstrap cluster.kubelet
:komponen yang berjalan di semua mesin di cluster Anda dan melakukan hal-hal seperti memulai POD dan container.kubectl
:utilitas baris perintah untuk berbicara dengan cluster Anda.
sudo apt-get update && sudo apt-get install -y apt-transport-https curl
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
cat <<EOF | sudo tee /etc/apt/sources.list.d/kubernetes.list
deb https://apt.kubernetes.io/ kubernetes-xenial main
EOF
sudo apt-get update
sudo apt-get install -y kubelet kubeadm kubectl
sudo apt-mark hold kubelet kubeadm kubectl
Konfirmasi versi yang diinstal
kubectl version --client
kubeadm version
Keluaran:
[email protected]:~$ kubectl version --client
Client Version: version.Info{Major:"1", Minor:"22", GitVersion:"v1.22.0", GitCommit:"c2b5237ccd9c0f1d600d3072634ca66cefdf272f", GitTreeState:"clean", BuildDate:"2021-08-04T18:03:20Z", GoVersion:"go1.16.6", Compiler:"gc", Platform:"linux/amd64"}
[email protected]:~$ kubeadm version
kubeadm version: &version.Info{Major:"1", Minor:"22", GitVersion:"v1.22.0", GitCommit:"c2b5237ccd9c0f1d600d3072634ca66cefdf272f", GitTreeState:"clean", BuildDate:"2021-08-04T18:02:08Z", GoVersion:"go1.16.6", Compiler:"gc", Platform:"linux/amd64"}
Matikan pertukaran.
sudo sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab
sudo swapoff -a
Konfigurasi sysctl.
sudo modprobe overlay
sudo modprobe br_netfilter
sudo tee /etc/sysctl.d/kubernetes.conf<<EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
EOF
sudo sysctl --system
Instal waktu proses Containerd Container
sudo apt-get install -y containerd
Konfigurasikan containerd dan mulai layanan
sudo mkdir -p /etc/containerd
sudo containerd config default > /etc/containerd/config.toml
Aktifkan layanan untuk memulai saat boot dan memulai
sudo systemctl enable --now containerd
# check status
sudo systemctl status containerd
Layanan harus berjalan
containerd.service - containerd container runtime
Loaded: loaded (/lib/systemd/system/containerd.service; enabled; vendor preset: enabled)
Active: active (running) since Wed 2021-08-04 20:27:51 UTC; 7min ago
Docs: https://containerd.io
Main PID: 8159 (containerd)
Tasks: 12
Memory: 23.3M
CGroup: /system.slice/containerd.service
└─8159 /usr/bin/containerd
Aug 04 20:27:51 ub-kubeadm containerd[8159]: time="2021-08-04T20:27:51.784407330Z" level=info msg="loading plugin \"io.containerd.grpc>
Aug 04 20:27:51 ub-kubeadm containerd[8159]: time="2021-08-04T20:27:51.785605392Z" level=info msg=serving... address=/run/containerd/c>
Aug 04 20:27:51 ub-kubeadm containerd[8159]: time="2021-08-04T20:27:51.785639559Z" level=info msg=serving... address=/run/containerd/c>
Aug 04 20:27:51 ub-kubeadm containerd[8159]: time="2021-08-04T20:27:51.787585658Z" level=info msg="containerd successfully booted in 0>
Aug 04 20:27:51 ub-kubeadm containerd[8159]: time="2021-08-04T20:27:51.801146245Z" level=info msg="Start subscribing containerd event"
Aug 04 20:27:51 ub-kubeadm containerd[8159]: time="2021-08-04T20:27:51.804843058Z" level=info msg="Start recovering state"
Aug 04 20:27:51 ub-kubeadm containerd[8159]: time="2021-08-04T20:27:51.805094249Z" level=info msg="Start event monitor"
Aug 04 20:27:51 ub-kubeadm containerd[8159]: time="2021-08-04T20:27:51.805193238Z" level=info msg="Start snapshots syncer"
Aug 04 20:27:51 ub-kubeadm containerd[8159]: time="2021-08-04T20:27:51.805282655Z" level=info msg="Start cni network conf syncer"
Aug 04 20:27:51 ub-kubeadm containerd[8159]: time="2021-08-04T20:27:51.805369362Z" level=info msg="Start streaming server"
Inisialisasi node master
Aktifkan dan mulai layanan kubelet.
sudo systemctl enable --now kubelet
Tarik gambar kontainer yang diperlukan:
sudo kubeadm config images pull
Setel nama DNS titik akhir cluster atau tambahkan catatan ke /etc/hosts
berkas.
192.168.20.7 k8s.citizix.local
Buat kluster:
sudo kubeadm init \
--pod-network-cidr=192.168.0.0/16 \
--control-plane-endpoint=k8s.citizix.local
Setelah selesai, k8s harus aktif dan berjalan. Dapatkan file admin kubeconfig dari jalur ini /etc/kubernetes/admin.conf
mkdir ~/.kube
sudo cp /etc/kubernetes/admin.conf ~/.kube/admin.conf
sudo chown ${USER}.${GROUP} ~/.kube/admin.conf
chmod 400 ~/.kube/admin.conf
Periksa status cluster:
kubectl cluster-info
Konfirmasi node master sudah siap:
kubectl get nodes -o wide
Node Master tambahan dapat ditambahkan menggunakan perintah di output instalasi:
kubeadm join k8s-cluster.computingforgeeks.com:6443 --token sr4l2l.2kvot0pfalh5o4ik \
--discovery-token-ca-cert-hash sha256:c692fb047e15883b575bd6710779dc2c5af8073f7cab460abd181fd3ddb29a18 \
--control-plane
Tambahkan node pekerja
Dengan bidang kontrol yang siap, Anda dapat menambahkan node pekerja ke kluster untuk menjalankan beban kerja terjadwal.
Jika alamat titik akhir tidak ada dalam DNS, tambahkan catatan ke /etc/hosts.
$ sudo vim /etc/hosts
192.168.20.7 k8s.citizix.local
Perintah join yang diberikan digunakan untuk menambahkan node pekerja ke cluster.
kubeadm join k8s-cluster.computingforgeeks.com:6443 \
--token sr4l2l.2kvot0pfalh5o4ik \
--discovery-token-ca-cert-hash sha256:c692fb047e15883b575bd6710779dc2c5af8073f7cab460abd181fd3ddb29a18
Jalankan perintah di bawah pada control-plane untuk melihat apakah node bergabung dengan cluster.
kubectl get nodes
Deploy aplikasi di cluster