Bagaimana menginstall sebuah Kubernetes Cluster on CentOS 7

Bagaimana menginstall sebuah Kubernetes Cluster on CentOS 7
February 22, 2023 No Comments Kubernetes G6k1JiPxqm


Lingkungan virtual kecil, yang disebut wadah , telah menjadi sangat diperlukan untuk mengembangkan dan mengelola aplikasi.

Mengerjakan aplikasi dalam wadah terisolasi tidak memengaruhi sistem operasi host. Wadah lebih efisien daripada mesin virtual karena tidak memerlukan sistem operasinya.

Kubernetes is an open-source platform that helps you deploy, scale, and manage resources across multiple containers.

Follow this tutorial and learn how to install Kubernetes on a CentOS 7 system.

Prerequisites

  • Multiple Linux servers running CentOS 7 (1 Master Node, Multiple Worker Nodes)
  • A user account on every system with sudo or root privileges
  • The yum package manager, included by default
  • Command-line/terminal window

Steps for Installing Kubernetes on CentOS 7

To use Kubernetes, you need to install a containerization engine. Currently, the most popular container solution is DockerDocker needs to be installed on CentOSboth on the Master Node and the Worker Nodes.

Step 1: Configure Kubernetes Repository

Kubernetes packages are not available from official CentOS 7 repositories. This step needs to be performed on the Master Node, and each Worker Node you plan on utilizing for your container setup. Enter the following command to retrieve the Kubernetes repositories.

cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
EOF

Note: If using the sudo command, append it not only to the cat command but to the restricted file as well.

Step 2: Install kubeletkubeadm, and kubectl

These 3 basic packages are required to be able to use Kubernetes. Install the following package(s) on each node:

sudo yum install -y kubelet kubeadm kubectl
systemctl enable kubelet
systemctl start kubelet

You have now successfully installed Kubernetes, including its tools and basic packages.

Sistem mengonfirmasi bahwa Anda telah menginstal kubeadm, kubectl, dan kubelet

Before deploying a cluster, make sure to set hostnames, configure the firewall, and kernel settings.

Step 3: Set Hostname on Nodes

To give a unique hostname to each of your nodes, use this command:

sudo hostnamectl set-hostname master-node

or

sudo hostnamectl set-hostname worker-node1

In this example, the master node is now named master-node, while a worker node is named worker-node1.

Make a host entry or DNS record to resolve the hostname for all nodes:

sudo vi /etc/hosts

With the entry:

192.168.1.10 master.phoenixnap.com master-node
192.168.1.20 node1. phoenixnap.com node1 worker-node

Step 4: Configure Firewall

The nodes, containers, and pods need to be able to communicate across the cluster to perform their functions. Firewalld is enabled in CentOS by default on the front-end. Add the following ports by entering the listed commands.

On the Master Node enter:

sudo firewall-cmd --permanent --add-port=6443/tcp
sudo firewall-cmd --permanent --add-port=2379-2380/tcp
sudo firewall-cmd --permanent --add-port=10250/tcp
sudo firewall-cmd --permanent --add-port=10251/tcp
sudo firewall-cmd --permanent --add-port=10252/tcp
sudo firewall-cmd --permanent --add-port=10255/tcp
sudo firewall-cmd --reload

Each time a port is added the system confirms with a ‘success’ message.

Menambahkan port ke pengecualian firewalld

Enter the following commands on each worker node:

sudo firewall-cmd --permanent --add-port=10251/tcp
sudo firewall-cmd --permanent --add-port=10255/tcp
firewall-cmd --reload

Step 5: Update Iptables Settings

Set the net.bridge.bridge-nf-call-iptables to ‘1’ in your sysctl config file. This ensures that packets are properly processed by IP tables during filtering and port forwarding.

cat <<EOF > /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sysctl --system

Step 6: Disable SELinux

The containers need to access the host filesystem. SELinux needs to be set to permissive mode, which effectively disables its security functions.

Use following commands to disable SELinux:

sudo setenforce 0
sudo sed -i ‘s/^SELINUX=enforcing$/SELINUX=permissive/’ /etc/selinux/config

Step 7: Disable SWAP

Lastly, we need to disable SWAP to enable the kubelet to work properly:

sudo sed -i '/swap/d' /etc/fstab
sudo swapoff -a

How to Deploy a Kubernetes Cluster

Note: Deploy a Kubernetes cluster using the BMC portal’s intuitive UI. Have an enterprise Kubernetes environment ready in minutes.

https://youtube.com/watch?v=evcOhLvoPdI%3Ffeature%3Doembed

Step 1: Create Cluster with kubeadm

Initialize a cluster by executing the following command:

sudo kubeadm init --pod-network-cidr=10.244.0.0/16

The process might take several minutes to complete based on network speed. Once this command finishes, it displays a kubeadm join message. Make a note of the entry and use it to join worker nodes to the cluster at a later stage.

Note: This tutorial uses the flannel virtual network add-on. The 10.244.0.0/16 network value reflects the configuration of the kube-flannel.yml file. If you plan to use a different third-party provider, change the --pod-network-cidr value to match your provider’s requirements.

Step 2: Manage Cluster as Regular User

To start using the cluster you need to run it as a regular user by typing:

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

Step 3: Set Up Pod Network

A Pod Network allows nodes within the cluster to communicate. There are several available Kubernetes networking options. Use the following command to install the flannel pod network add-on:

sudo kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml

Jika Anda memutuskan untuk menggunakan flanel, edit aturan firewall Anda untuk mengizinkan lalu lintas untuk port default flanel 8285 .

Langkah 4: Periksa Status Cluster

Periksa status node dengan memasukkan perintah berikut di server master:

sudo kubectl get nodes

Setelah jaringan pod diinstal, Anda dapat mengonfirmasi bahwa itu berfungsi dengan memeriksa apakah pod CoreDNS sedang berjalan dengan mengetik:

sudo kubectl get pods --all-namespaces

Langkah 5: Gabung Node Pekerja ke Cluster

Seperti yang ditunjukkan pada Langkah 1 , Anda dapat menggunakan kubeadm join perintah pada setiap node pekerja untuk menghubungkannya ke cluster.

kubeadm join --discovery-token cfgrty.1234567890jyrfgd --discovery-token-ca-cert-hash sha256:1234..cdef 1.2.3.4:6443

Ganti kode dengan kode dari server master Anda. Ulangi tindakan ini untuk setiap node pekerja di cluster Anda.

Kesimpulan

Anda telah berhasil menginstal Kubernetes di CentOS dan sekarang dapat mengelola cluster di beberapa server. Jika Anda memiliki server bare metal, Anda mungkin ingin melihat panduan kami tentang cara menginstal Kubernetes di server tersebut .

Tutorial Kubernetes ini memberikan titik awal yang baik untuk menjelajahi banyak opsi yang ditawarkan platform serbaguna ini. Gunakan Kubernetes untuk menskalakan operasi Anda secara lebih efisien dan menghabiskan lebih sedikit waktu untuk pengelolaan mikro kontainer.

Untuk pemula yang masih belum memiliki pengalaman menerapkan banyak kontainer,  Minikube  adalah cara yang bagus untuk memulai. Minikube  adalah sistem untuk menjalankan cluster node tunggal secara lokal dan sangat bagus untuk mempelajari dasar-dasarnya, sebelum beralih ke Kubernetes.

About The Author

Leave a reply

Your email address will not be published. Required fields are marked *