Appendix_A_docker_k8s_install
Appendix A: Docker and Kubernetes Installation Guide
This guide provides steps for installing Docker and setting up a Kubernetes cluster using kubeadm. These instructions may require adjustments based on your specific Linux distribution and version.
Part 1: Docker Installation
1.1 Prepare Hosts and Install Docker
sudo apt update -y
sudo apt install -y \
docker.io \
watch \
ipset \
tcpdump \
jq1.2 Enable Docker
Ensure Docker is enabled to start on boot and check the installed version.
sudo systemctl enable docker
sudo systemctl start docker # Ensure Docker service is running
sudo docker --version1.3 Alternative Docker Installation (Using Docker's Official Script)
Alternatively, you can install Docker using the official convenience script from Docker.
Part 2: Kubernetes Installation (using kubeadm)
2.1 Install kubeadm and Related Tools on All Nodes (Master and Workers)
These steps should be performed on all machines that will be part of your Kubernetes cluster.
Disable Swap: Kubernetes requires swap to be disabled.
Install kubeadm, kubelet, and kubectl: Refer to the official Kubernetes documentation for installing these packages for your specific OS version, as the repository used in Docker setup might be outdated for current kubeadm. Assuming
apt.kubernetes.iois correctly configured for a compatible version (orpkgs.k8s.io):Verify installation:
Pull Required Images (Optional but Recommended): This step downloads the container images kubeadm will use, which can speed up
kubeadm initandkubeadm join.
2.2 Initialize the Master Node
Perform these steps only on the machine designated as the master node.
Determine Master Node's Internal IP: The following command attempts to get the IP from
eth1. Adjust the interface name (eth1) if your primary network interface is different (e.g.,ens160,enp0s3).If
$MASTER_INTERNAL_IPis empty or incorrect, set it manually.Initialize Kubernetes Control Plane: Adjust
--apiserver-cert-extra-sansif you have a specific DNS name for your master node or a load balancer.(Replaced specific FQDN with a placeholder and used
$(hostname -f))Post-Initialization Steps:
CRITICAL: After
kubeadm initfinishes, it will output akubeadm joincommand. You must copy this entire command and save it. You will need it to join worker nodes to the cluster. It will look something like this (your token and hash will be different):Configure kubectl for Admin Access: The
/etc/kubernetes/admin.conffile contains credentials providing administrative access to your cluster.This configuration grants full control over the cluster. Handle it securely.
Monitor Node Status (Optional): Open another terminal or run in the background to watch nodes join. Initially, the master node might show "NotReady" until a CNI is installed.
2.3 Join Worker Nodes
Perform these steps on each machine designated as a worker node. Ensure steps from "2.1 Install kubeadm and Related Tools on All Nodes" have been completed on each worker.
Use the Saved
kubeadm joinCommand: Execute thekubeadm joincommand that you saved from thekubeadm initoutput on the master node. It will look like:(The original document mentioned "---- copy the print join command ---". This clarifies that it's the command from the master's init.)
2.4 Install a Container Network Interface (CNI) Plugin
This step is performed on the master node after worker nodes have (or are starting to) join. Pod networking is required for pods to communicate and for nodes to become "Ready".
Apply Calico CNI Manifest: Calico is a popular CNI choice. Ensure your chosen
--pod-network-cidrinkubeadm init(e.g.,192.168.0.0/16) is compatible with the CNI plugin's default configuration or update the CNI manifest accordingly.Verify Node Status: After a few minutes, nodes should transition to the "Ready" state.
Last updated