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.
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/configInstall Docker CE
Docker CE (Community Edition) is used.
1. Install yum utilities:
# yum install -y yum-utils device-mapper-persistent-data lvm22. Add the Docker CE repository:
# yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo3. 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-worldInstall 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.io2. 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
EOF3. Install the required packages:
# yum install -y kubectl kubelet kubeadm kubernetes-cniConfigure 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 kubeletInitialize 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/16After 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/configInstall 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.ymlJoin Worker Nodes
Use the token printed at the end of kubeadm init (example below):
# kubeadm join --token 0696ed.7cd261f787453bd9 192.168.0.100:6443Verify Cluster Status
# kubectl get nodes
# kubectl get pods -n kube-systemIf 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)
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.
21CTO
21CTO (21CTO.com) offers developers community, training, and services, making it your go‑to learning and service platform.
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.
