هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.
$ مستخدم عادي# بصلاحية root (أو مع sudo)
Know it before you install
Every node runs a container runtime (containerd) and the kubelet. On the control plane, kubeadm init starts the API server, etcd, the scheduler and the controller manager as static Pods. Workers join with a token. A CNI plugin (Flannel, Calico, Cilium) gives the Pods their network.
| Item | Value |
|---|---|
| Packages | kubeadm, kubelet, kubectl (from pkgs.k8s.io), containerd |
| Services | kubelet.service, containerd.service |
| Cluster config | /etc/kubernetes/ (admin.conf, manifests/, pki/) |
| etcd data | /var/lib/etcd/ |
| kubelet | /var/lib/kubelet/config.yaml, logs: journalctl -u kubelet |
| Control plane ports | 6443 (API), 2379–2380 (etcd), 10250 (kubelet), 10257, 10259 |
| Worker ports | 10250 (kubelet), 30000–32767 (NodePort services) |
What you need (each node):
- RHEL / Rocky / Alma 9–10 or Ubuntu 22.04 / 24.04, at least 2 CPU and 2 GB RAM (control plane), a unique hostname, MAC and
product_uuid. - Full network between all nodes; a fixed IP for the control plane.
- The same Kubernetes minor version on all nodes (this guide: 1.33 — change
v1.33in the URLs to the version you want).
Prepare every node
Do these steps on all nodes (control plane and workers). Turn off swap (the kubelet does not start with swap by default):
Load the kernel modules and set the network settings that Kubernetes needs:
cat > /etc/modules-load.d/k8s.conf <<'EOF'
overlay
br_netfilter
EOF
modprobe overlay
modprobe br_netfilter
cat > /etc/sysctl.d/k8s.conf <<'EOF'
net.bridge.bridge-nf-call-iptables = 1
net.bridge.bridge-nf-call-ip6tables = 1
net.ipv4.ip_forward = 1
EOF
sysctl --systemGive every node a name in DNS or in /etc/hosts on all nodes:
192.0.2.10 cp1
192.0.2.21 worker1
192.0.2.22 worker2Install containerd
On RHEL, use the containerd.io package from the Docker repository; on Ubuntu, the containerd package of Ubuntu is fine:
dnf config-manager --add-repo https://download.docker.com/linux/rhel/docker-ce.repo
dnf -y install containerd.io
apt-get update && apt-get install -y containerdMake the default config and switch on the systemd cgroup driver — the kubelet uses systemd, and both must match:
mkdir -p /etc/containerd
containerd config default > /etc/containerd/config.toml
sed -i 's/SystemdCgroup = false/SystemdCgroup = true/' /etc/containerd/config.toml
systemctl enable --now containerd
systemctl restart containerdانتبه
The containerd.io package writes a config that turns off the CRI plugin. The containerd config default step above replaces it — do not skip it.
Install kubeadm, kubelet and kubectl on RHEL
cat > /etc/yum.repos.d/kubernetes.repo <<'EOF'
[kubernetes]
name=Kubernetes
baseurl=https://pkgs.k8s.io/core:/stable:/v1.33/rpm/
enabled=1
gpgcheck=1
gpgkey=https://pkgs.k8s.io/core:/stable:/v1.33/rpm/repodata/repomd.xml.key
exclude=kubelet kubeadm kubectl cri-tools kubernetes-cni
EOF
setenforce 0
sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config
dnf -y install kubelet kubeadm kubectl --disableexcludes=kubernetes
systemctl enable --now kubeletOpen the firewall (control plane; on workers open 10250 and 30000–32767):
firewall-cmd --permanent --add-port={6443,2379-2380,10250,10257,10259}/tcp
firewall-cmd --reloadملاحظة
The exclude= line stops a normal dnf upgrade from changing the Kubernetes packages — cluster upgrades must be done on purpose with kubeadm. The Kubernetes docs set SELinux to permissive for kubeadm clusters.
Install kubeadm, kubelet and kubectl on Ubuntu
apt-get install -y apt-transport-https ca-certificates curl gpg
mkdir -p -m 755 /etc/apt/keyrings
curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.33/deb/Release.key | gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg
echo 'deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.33/deb/ /' > /etc/apt/sources.list.d/kubernetes.list
apt-get update
apt-get install -y kubelet kubeadm kubectl
apt-mark hold kubelet kubeadm kubectl
systemctl enable --now kubeletتذكّر
The kubelet now restarts every few seconds. That is normal: it waits for kubeadm init or kubeadm join to give it a config.
Create the cluster
On the control plane only. The Pod network range must match the CNI plugin (Flannel uses 10.244.0.0/16):
kubeadm config images pull
kubeadm init --pod-network-cidr=10.244.0.0/16 --apiserver-advertise-address=192.0.2.10
Your Kubernetes control-plane has initialized successfully!
...
kubeadm join 192.0.2.10:6443 --token abcdef.0123456789abcdef \
--discovery-token-ca-cert-hash sha256:1f2e...Give your normal user the admin kubeconfig:
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
kubectl get nodes
NAME STATUS ROLES AGE VERSION
cp1 NotReady control-plane 1m v1.33.5NotReady is expected now: there is no Pod network yet. Install Flannel:
kubectl apply -f https://github.com/flannel-io/flannel/releases/latest/download/kube-flannel.yml
kubectl get pods -A
kubectl get nodes
NAME STATUS ROLES AGE VERSION
cp1 Ready control-plane 3m v1.33.5في العمل
Flannel is the simplest CNI, but it does not enforce NetworkPolicies. For real clusters choose Calico or Cilium (with the Pod CIDR they expect) when you need network policies.
Join the worker nodes
On each worker, run the kubeadm join line from the init output. The token is valid 24 hours; make a new line any time on the control plane:
kubeadm token create --print-join-command
kubeadm join 192.0.2.10:6443 --token abcdef.0123456789abcdef --discovery-token-ca-cert-hash sha256:1f2e...
kubectl get nodes -o wide
kubectl label node worker1 node-role.kubernetes.io/worker=Test the cluster with a small app:
kubectl create deployment web --image=nginx:1.27 --replicas=2
kubectl expose deployment web --port=80 --type=NodePort
kubectl get svc web
curl -I http://worker1:31234(Use the NodePort that kubectl get svc shows.)
Daily work: backups, certificates and upgrades
Back up etcd — the whole cluster state — often, and copy the file off the node:
ETCDCTL_API=3 etcdctl --endpoints=https://127.0.0.1:2379 --cacert=/etc/kubernetes/pki/etcd/ca.crt --cert=/etc/kubernetes/pki/etcd/server.crt --key=/etc/kubernetes/pki/etcd/server.key snapshot save /backup/etcd-$(date +%F).db
kubeadm certs check-expirationCertificates last one year; kubeadm upgrade renews them. Upgrade one minor version at a time (1.33 → 1.34): change the repo URL to the new version, then on the control plane:
dnf -y install kubeadm-1.34.* --disableexcludes=kubernetes
kubeadm upgrade plan
kubeadm upgrade apply v1.34.1
kubectl drain cp1 --ignore-daemonsets
dnf -y install kubelet-1.34.* kubectl-1.34.* --disableexcludes=kubernetes
systemctl daemon-reload && systemctl restart kubelet
kubectl uncordon cp1On each worker: install the new kubeadm, run kubeadm upgrade node, drain the node, upgrade kubelet, restart it and uncordon. (Ubuntu: apt-mark unhold, apt-get install kubeadm=1.34.1-1.1, then hold again.)
Make it safe
Security checklist:
admin.confis the master key: keep it on the control plane, give people their own RBAC users.- Back up etcd (encrypted, off the node) and test the restore.
- Use a CNI with NetworkPolicy support; start with a default-deny policy per namespace.
- Pod Security Admission: label namespaces with
pod-security.kubernetes.io/enforce=restricted(orbaseline). - Encrypt Secrets at rest (
EncryptionConfigurationfor the API server). - Firewall: 6443 only from admin and node networks; etcd ports only between control plane nodes.
- Upgrade at least once a year (each minor version gets about 14 months of fixes). Check with
kube-bench.
Remove a node or the cluster
Fix common problems
| Problem | Cause | Fix |
|---|---|---|
Node stays NotReady | No CNI plugin, or it fails. | kubectl get pods -n kube-flannel; journalctl -u kubelet; install the CNI. |
[ERROR Swap] or kubelet will not start | Swap is on. | swapoff -a and comment the swap line in /etc/fstab. |
container runtime is not running | containerd stopped or its CRI plugin is off. | Make the default config (see above), restart containerd. |
| Pods restart again and again, API server unstable | cgroup driver mismatch. | SystemdCgroup = true in containerd config; restart containerd and kubelet. |
[ERROR FileContent--proc-sys-net-ipv4-ip_forward] | IP forwarding is off. | The sysctl file above, then sysctl --system. |
kubeadm join fails with token error | The token expired (24 h). | kubeadm token create --print-join-command. |
x509: certificate has expired | Certificates are older than one year. | kubeadm certs renew all, then restart the control plane Pods. |
CoreDNS Pending | No CNI yet. | Install the CNI; CoreDNS starts after it. |
Next steps
- Quick how-tos: Find why a Pod does not start, Back up and restore etcd, Create a Secret safely, Drain a node, Upgrade a kubeadm cluster.
- The client: Install and set up kubectl. Packages for the cluster: Install and set up Helm.
- The full course: CKA summary — Install the cluster, Maintain it, Troubleshoot.
- Practise: Lab: back up etcd, break the cluster, restore it.
- Command pages: kubectl, etcdctl, crictl, kube-bench.
- A smaller cluster for labs: Command page: k3s, Command page: minikube.
1A new node is NotReady right after kubeadm init. Is something broken?
No. The Pod network (CNI) is missing. Install it, and the node becomes Ready.
2Why must containerd use SystemdCgroup = true?
The kubelet uses the systemd cgroup driver. Both must use the same driver, or Pods become unstable.