- deb/rpm-compatible OS
- e.g., Ubuntu 16.04+, CentOS 7, Debian 9+, etc.
- Hardware
- 2 CPUs or more on the control-plane node
- 2 GB or more of RAM per machine
- Network
- Full network connectivity among all machines in the cluster. A public or private network is fine.
- Certain ports are open on your machines. See here for more details.
- Other
- Unique hostname, MAC address, and product_uuid for every node. See here for more details.
- Swap disabled
- All my VM machines are based on Ubuntu 16.04 LTS, running on the Google Cloud Platform.
Node | CPU cores | RAM | IP address |
---|---|---|---|
master | 4 | 15G | - |
slave1 | 2 | 7.5G | - |
slave2 | 2 | 7.5G | - |
This doc is mainly for Ubuntu 16.04, the commands may differ if you're using other distro.
- In order to run kubelet properly, you must disable swap on all the machines.
sudo swapoff -a // disable swap for all devices
sudo free -m // make sure swap is unused
- Change the nameserver to
8.8.8.8
(Google Public DNS) for all the machines.
vi /etc/resolv.conf
- Install Docker on all the machines.
- This step could take a while...
apt-get update && apt-get install -y docker.io
apt-get update && apt-get install -y apt-transport-https
curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
cat <<EOF >/etc/apt/sources.list.d/kubernetes.list
deb http://apt.kubernetes.io/ kubernetes-xenial main
EOF
apt-get update
apt-get install -y kubelet kubeadm kubectl
10.244.0.0/16
: flannel network
kubeadm init --apiserver-advertise-address <masterIP> --pod-network-cidr=10.244.0.0/16
- After executing this command, don't forget to save the command under
Your Kubernetes master has initialized successfully!
- Copy and paste the command in the previous step.
- Enable kubectl auto-complete feature
echo 'source <(kubectl completion bash)' >>~/.bashrc
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
- After
kubeadm init
, there're command to join. - If you miss that, run
kubeadm token list
.
kubeadm join --token <token> <masterIP:port>
kubectl get nodes
kubectl get pods --all-namespaces
kubectl describe pods <podName> kube-flannel --namespace=kube-system // show detail
- Installing kubeadm - Kubernetes
- Creating a single control-plane cluster with kubeadm - Kubernetes
- How do I disable swap? - Ask Ubuntu
kubectl get pods // 先取得 Pod Name
kubectl exec <httpd_pod_name> -it -- /bin/sh
// 上述的例子中 Pod 內只有一個 Container,但如果今天 Pod 內有多個 container,需要在後方加上 -c <container_name>
kubectl exec <httpd_pod_name> -it -c <container_name> -- /bin/sh
- 書中的內容較舊,因此部份檔案可能需要修改
- 但老師有放修正後的檔案在
192.168.60.15/docker/k8s
資料夾中