Cloud Native 9 min read

Kubernetes Cluster Setup: Environment Preparation and Master Node Initialization

This guide walks through preparing three CentOS servers—configuring hostnames, disabling firewalls and swap, setting up Docker and Kubernetes repositories, installing Docker and Kubernetes components, adjusting kernel parameters, and finally initializing the Kubernetes master with kubeadm before joining worker nodes.

Practical DevOps Architecture
Practical DevOps Architecture
Practical DevOps Architecture
Kubernetes Cluster Setup: Environment Preparation and Master Node Initialization

Prepare the three servers (master, node‑1, node‑2) by assigning hostnames and IPs, disabling firewalld ( systemctl stop firewalld && systemctl disable firewalld ), turning off SELinux ( sed -i 's/enforcing/disabled/' /etc/selinux/config && setenforce 0 ), and disabling swap ( swapoff -a and editing /etc/fstab ).

Update /etc/hosts with the hostname‑IP mappings and configure bridge traffic to be processed by iptables by creating /etc/sysctl.d/k8s.conf containing: net.bridge.bridge-nf-call-ip6tables = 1 net.bridge.bridge-nf-call-iptables = 1 Then apply with sysctl --system .

Set up Alibaba Cloud YUM mirrors for Docker and Kubernetes: download the Docker repo file to /etc/yum.repos.d/docker-ce.repo and create /etc/yum.repos.d/kubernetes.repo with the appropriate baseurl and GPG keys.

Install Docker ( yum -y install docker-ce-18.06.1.ce-3.el7 ) and enable it ( systemctl enable docker && systemctl start docker ). Install Kubernetes binaries ( yum install -y kubelet-1.19.3 kubeadm-1.19.3 kubectl-1.19.3 ipvsadm ) and configure /etc/sysconfig/kubelet to ignore swap ( KUBELET_EXTRA_ARGS="--fail-swap-on=false" ).

Apply additional kernel parameters ( net.ipv4.ip_forward = 1 ) by adding them to /etc/sysctl.d/k8s.conf and reloading. Enable and start kubelet ( systemctl enable kubelet && systemctl start kubelet ).

Initialize the control plane on the master node with a kubeadm init command, for example: kubeadm init \ --apiserver-advertise-address=192.168.210.85 \ --image-repository=registry.aliyuncs.com/google_containers \ --kubernetes-version=v1.19.3 \ --service-cidr=10.1.0.0/16 \ --pod-network-cidr=10.2.0.0/16 \ --ignore-preflight-errors=NumCPU,Swap This creates certificates, etcd, kube‑apiserver, controller‑manager, scheduler, and writes configuration files.

The guide explains each kubeadm phase (init, preflight, kubelet‑start, certificates, kubeconfig, control‑plane, etcd, wait‑control‑plane, apiclient, uploadconfig, kubelet, patchnode, mark‑control‑plane, bootstrap‑token, add‑ons) and what resources they generate.

After a successful init, copy the admin kubeconfig to a regular user’s $HOME/.kube/config ( mkdir -p $HOME/.kube && cp -i /etc/kubernetes/admin.conf $HOME/.kube/config && chown $(id -u):$(id -g) $HOME/.kube/config ), then deploy a pod network (e.g., Calico) with kubectl apply -f [podnetwork].yaml . Finally, join the worker nodes using the token command shown by kubeadm, such as: kubeadm join 192.168.210.85:6443 --token --discovery-token-ca-cert-hash sha256: .

The article also includes several screenshots illustrating the steps and notes that users should check logs for any errors during the process.

Cloud NativeDockerKubernetesCluster SetupCentOSkubeadm
Practical DevOps Architecture
Written by

Practical DevOps Architecture

Hands‑on DevOps operations using Docker, K8s, Jenkins, and Ansible—empowering ops professionals to grow together through sharing, discussion, knowledge consolidation, and continuous improvement.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.