準備工作
- 機器可以科學上網
docker設置http代理
參考官方文檔: https://docs.docker.com/config/daemon/systemd/#httphttps-proxy
步驟如下:mkdir -p /etc/systemd/system/docker.service.d touch /etc/systemd/system/docker.service.d/http-proxy.conf cat <<EOF > /etc/systemd/system/docker.service.d/http-proxy.conf [Service] Environment="HTTP_PROXY=http://127.0.0.1:8123/" "HTTPS_PROXY=https://127.0.0.1:8123/" "NO_PROXY=localhost,127.0.0.1,本機IP,10.96.0.0/12,10.244.0.0/16" EOF systemctl daemon-reload systemctl restart docker systemctl show --property=Environment docker
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
確保機器正確設置http代理
- 需要設置no_proxy,過濾掉本機IP(包括127.0.0.1、localhost、本機實際IP、10.96.0.0/12、10.244.0.0/16)
- 確保開機啓動時,第一時間再加這3個環境變量
- ubuntu,可以在 /etc//etc/environment 中export它們
- centos,可以在 /etc/profile.d/proxy.sh 中export它們
設置hostname的IP
/etc/hosts中添加 本機IP hostname的域名解析條目關閉linux swap
vim /etc/fstab (註釋swap那行) echo "vm.swappiness = 0">> /etc/sysctl.conf swapoff -a
- 1
- 2
- 3
- docker關閉selinux
vim /etc/docker/daedom.json
增加 “selinux-enabled”: false
安裝kubeadm
參考官方文檔: https://kubernetes.io/docs/tasks/tools/install-kubeadm/#before-you-begin
根據自己系統,選擇裏面對應的命令依次執行即可。
使用kubeadm,搭建k8s環境
參考官方文檔:https://kubernetes.io/docs/setup/independent/create-cluster-kubeadm/
設置docker insecure-registries參數
"insecure-registries" : ["gcr.io"],
- 1
預下載k8s鏡像
參考官方文檔:https://github.com/kubernetes/kubeadm/blob/master/vagrant/box.mddocker pull k8s.gcr.io/pause-amd64:3.1 docker pull k8s.gcr.io/etcd-amd64:3.1.12 docker pull k8s.gcr.io/kube-apiserver-amd64:v1.10.2 docker pull k8s.gcr.io/kube-scheduler-amd64:v1.10.2 docker pull k8s.gcr.io/kube-controller-manager-amd64:v1.10.2 docker pull k8s.gcr.io/kube-proxy-amd64:v1.10.2 docker pull k8s.gcr.io/k8s-dns-dnsmasq-nanny-amd64:1.14.8 docker pull k8s.gcr.io/k8s-dns-sidecar-amd64:1.14.8 docker pull k8s.gcr.io/k8s-dns-kube-dns-amd64:1.14.8
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
執行kubeadm init命令
kubeadm reset kubeadm init --kubernetes-version=v1.10.2 --apiserver-advertise-address=172.19.11.210 --feature-gates=CoreDNS=true --pod-network-cidr=10.244.0.0/16
- 1
- 2
等待2分鐘左右,界面輸出:
到此,安裝kubernets成功!深坑,切記!在阿里雲環境下,需要注意 kubeadm init 命令的 –apiserver-advertise-address 參數,必須填內網IP,填寫外網IP將無法啓動成功!
kubectl設置帳號權限
如果是普通用戶,執行:mkdir -p $HOME/.kube sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config sudo chown $(id <span class="hljs-attribute">-u</span>):$(id -g) $HOME/.kube/config
- 1
- 2
- 3
如果是root帳號,執行:
export KUBECONFIG=/etc/kubernetes/admin.conf
- 1
安裝pod網絡代理
官方參考文檔:https://kubernetes.io/docs/concepts/cluster-administration/addons/大多數網絡代理,需要設置net.bridge.bridge-nf-call-iptables,如:
cat <<EOF > /etc/sysctl.d/k8s.conf net.bridge.bridge-nf-call-ip6tables = 1 net.bridge.bridge-nf-call-iptables = 1 EOF sysctl --system
- 1
- 2
- 3
- 4
- 5
如果選擇flannel作爲pod網絡代理,則執行:
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
- 1
查看是否安裝成功:
kubectl get pod -n kube-system -o wide
- 1
Master可以被調度(可選)
單機開發等,需要master機也可以開pod,那麼執行下面語句:kubectl taint nodes --all node-role.kubernetes.io/master-
- 1
加入節點
略
<link rel="stylesheet" href="https://csdnimg.cn/release/phoenix/template/css/markdown_views-ea0013b516.css">
</div>