Step-by-Step Guide to Setting Up a Kubernetes Cluster (Master and Node) on CentOS
This guide provides a comprehensive, command‑by‑command procedure for preparing a CentOS system, installing Docker and Kubernetes components, configuring networking and security settings, and deploying both master and worker nodes along with the Kubernetes Dashboard.
Public Configuration
1. Update Operating System
yum -y update
reboot2. Modify hosts
192.168.172.132 node01.example.com
192.168.172.133 node02.example.com3. Password‑less SSH
ssh-keygen
ssh-copy-id node01.example.com
ssh-copy-id node02.example.com
scp /etc/hosts node02.example.com:/etc4. Disable Firewall
systemctl stop firewalld && systemctl disable firewalld5. Disable SELinux
sed -i "s/^SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
setenforce 0
# Disable swap
swapoff -a && sed -i 's/.*swap.*/#&/' /etc/fstab6. Enable IPv4 Forwarding
cat > /etc/sysctl.d/k8s.conf <<EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
EOF
modprobe br_netfilter
sysctl -p /etc/sysctl.d/k8s.conf7. Configure yum Repositories
cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo -O /etc/yum.repos.d/docker-ce.repo8. Install Packages
yum install -y docker-ce-18.06.1.ce-3.el7
systemctl enable docker && systemctl start docker
docker version
yum install -y kubelet kubeadm kubectlInstall Master Node
kubeadm init --kubernetes-version=1.15.3 \
--apiserver-advertise-address=192.168.172.132 \
--image-repository registry.aliyuncs.com/google_containers \
--service-cidr=10.1.0.0/16 \
--pod-network-cidr=10.244.0.0/16
systemctl start kubelet && systemctl enable kubelet
mkdir -p /root/.kube
cp /etc/kubernetes/admin.conf /root/.kube/config
kubectl get nodes
# Install Flannel CNI
docker pull quay.io/coreos/flannel:v0.11.0-amd64
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
kubectl get nodesInstall Worker Node
kubeadm join 192.168.172.132:6443 --token pk96e8.6irwnsmmf8kt8ncz \
--discovery-token-ca-cert-hash sha256:56dfb7749305372a51578578983ba628453732aa7655bdd763f43f707359e0d88dInstall Kubernetes Dashboard
wget https://raw.githubusercontent.com/kubernetes/dashboard/v1.10.1/src/deploy/recommended/kubernetes-dashboard.yaml
# Modify image and service type
image: registry.aliyuncs.com/google_containers/kubernetes-dashboard-amd64:v1.10.1
type: NodePort
docker pull registry.aliyuncs.com/google_containers/kubernetes-dashboard-amd64:v1.10.1
kubectl create -f kubernetes-dashboard.yaml
kubectl create serviceaccount dashboard-admin -n kube-system
kubectl create clusterrolebinding dashboard-admin --clusterrole=cluster-admin --serviceaccount=kube-system:dashboard-admin
kubectl describe secrets -n kube-system $(kubectl -n kube-system get secret | awk '/dashboard-admin/{print $1}')Reference documentation: https://mp.weixin.qq.com/s/vnriX2bTtnkv8i2UpLeNnA
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
DevOps Cloud Academy
Exploring industry DevOps practices and technical expertise.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
