Cloud Native 14 min read

Step‑by‑Step Guide: Build a Kubernetes Development Environment on CentOS

This tutorial walks you through setting up a complete Kubernetes development environment on CentOS, covering prerequisite installations, Docker CE setup, kubelet/kubeadm/kubectl configuration, master node initialization, network add‑ons, node joining, and common troubleshooting tips.

21CTO
21CTO
21CTO
Step‑by‑Step Guide: Build a Kubernetes Development Environment on CentOS

Prerequisites

1. Install net-tools: # yum install -y net-tools 2. Disable the firewall and SELinux:

# systemctl stop firewalld && systemctl disable firewalld
# setenforce 0
# sed -i 's/^SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config

Install Docker CE

Docker CE (Community Edition) is used.

1. Install yum utilities:

# yum install -y yum-utils device-mapper-persistent-data lvm2

2. Add the Docker CE repository:

# yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

3. Disable the edge repository and enable the stable one: # yum-config-manager --disable docker-ce-edge 4. Refresh the yum cache: # yum makecache fast 5. Install Docker CE: # yum -y install docker-ce 6. Run the hello‑world container to verify the installation:

# systemctl start docker
# docker run hello-world

Install Kubernetes Packages

1. (Optional) Use DaoCloud mirror to speed up downloads:

# curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://0d236e3f.m.daocloud.io

2. Add the Kubernetes yum repository (Aliyun mirror example):

# 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=0
EOF

3. Install the required packages:

# yum install -y kubectl kubelet kubeadm kubernetes-cni

Configure cgroups

Edit /etc/systemd/kubelet.service.d/10-kubeadm.conf and change the driver:

KUBELET_CGROUP_ARGS="--cgroup-driver=systemd" → KUBELET_CGROUP_ARGS="--cgroup-driver=cgroupfs"

Also adjust the cAdvisor port if needed:

Environment="KUBELET_CADVISOR_ARGS=--cadvisor-port=4194"

Start kubelet on all hosts

# systemctl enable kubelet && systemctl start kubelet

Initialize the Master Node

# kubeadm reset && kubeadm init \
  --apiserver-advertise-address=192.168.0.100 \
  --kubernetes-version=v1.7.5 \
  --pod-network-cidr=10.200.0.0/16

After a successful init, copy the admin kubeconfig for the regular user:

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

Install a Pod Network (Flannel)

# docker pull quay.io/coreos/flannel:v0.8.0-amd64
# kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/v0.8.0/Documentation/kube-flannel.yml
# kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/v0.8.0/Documentation/kube-flannel-rbac.yml

Join Worker Nodes

Use the token printed at the end of kubeadm init (example below):

# kubeadm join --token 0696ed.7cd261f787453bd9 192.168.0.100:6443

Verify Cluster Status

# kubectl get nodes
# kubectl get pods -n kube-system

If you encounter “connection refused to server localhost:8080”, set the kubeconfig environment variable: export KUBECONFIG=/etc/kubernetes/admin.conf Author: ChamPly (source: https://my.oschina.net/ChamPly/blog/1575888)

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Cloud NativeKuberneteskubeletcontainer orchestrationCentOSkubeadm
21CTO
Written by

21CTO

21CTO (21CTO.com) offers developers community, training, and services, making it your go‑to learning and service platform.

0 followers
Reader feedback

How this landed with the community

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.