首先安裝docker
sudo apt-get update && apt-get install -y apt-transport-https
sudo apt install docker.io
sudo systemctl start docker
sudo systemctl enable docker
添加k8s官方源
sudo curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add
deb http://apt.kubernetes.io/ kubernetes-xenial main
apt-get update
apt-get install -y kubelet kubeadm kubectl kubernetes-cni
這一步需要科學上網,否則會出現下載失敗。
使用kubeadm部署k8s
kubeadm init \
--image-repository registry.aliyuncs.com/google_containers \
--kubernetes-version v1.14.0 \
--pod-network-cidr=10.244.0.0/16
設置k8s的網絡插件
如果不安裝網絡插件的話,kubectl get pods -n kube-system
會有pod是polling狀態。
我們使用weave作爲網絡插件,執行下面命令安裝
kubectl apply -f "https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d '\n')"
設置k8s的存儲插件
我們使用rook作爲k8s的存儲插件,執行下面的命令
kubectl apply -f https://raw.githubusercontent.com/rook/rook/master/cluster/examples/kubernetes/ceph/common.yaml
kubectl apply -f https://raw.githubusercontent.com/rook/rook/master/cluster/examples/kubernetes/ceph/cluster.yaml
kubectl apply -f https://raw.githubusercontent.com/rook/rook/master/cluster/examples/kubernetes/ceph/operator.yaml
設置kubectl的自動補全
bash
執行
echo 'source <(kubectl completion bash)' >>~/.bashrc
kubectl completion bash >/etc/bash_completion.d/kubectl
zsh
編輯~/.zshrc文件,添加下面內容
autoload -Uz compinit
compinit
source <(kubectl completion zsh