Skip to content

Instantly share code, notes, and snippets.

@istar0me
Created December 18, 2019 22:39
Show Gist options
  • Save istar0me/d1dc9aefc8c43daaebea269346352e8c to your computer and use it in GitHub Desktop.
Save istar0me/d1dc9aefc8c43daaebea269346352e8c to your computer and use it in GitHub Desktop.

W15 20191217

Disclaimer: The doc isn't completed.

Environment

Prerequisite

  • 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

My Configuration

  • 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 -

Install Kubernetes

This doc is mainly for Ubuntu 16.04, the commands may differ if you're using other distro.

Disable Swap

  • 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

Configure DNS Server

  • Change the nameserver to 8.8.8.8 (Google Public DNS) for all the machines.
vi /etc/resolv.conf

Install Docker

  • Install Docker on all the machines.
  • This step could take a while...
apt-get update && apt-get install -y docker.io

Install Kubelet, kubeadm and kubectl

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

Create Cluster with Kubeadm

Initialize Master Node

  • 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!

Configure Kubectl

  • Copy and paste the command in the previous step.

  • Enable kubectl auto-complete feature
echo 'source <(kubectl completion bash)' >>~/.bashrc

Install Pod Network (flannel)

kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml

Join slave1, slave2 to cluster

  • After kubeadm init, there're command to join.
  • If you miss that, run kubeadm token list.
kubeadm join --token <token> <masterIP:port>

Get Node Status

kubectl get nodes

kubectl get pods --all-namespaces

kubectl describe pods <podName> kube-flannel --namespace=kube-system // show detail

Reference


雜記

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 資料夾中
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment