首先說下爲何選擇這個版本,由於這個版本是目前k8s1.10分支中最穩定的版本,其次是k8s dashboard支持得比較好的版本,並且是比較成熟的版本,因此選擇了這個版本node
首先咱們初始化下新安裝的系統,我有兩臺機器python
下面的操做兩臺機器都要操做linux
使用我下面這個腳本關閉firewalld什麼的git
curl -O https://raw.githubusercontent.com/bboysoulcn/centos/master/centos.sh
github
********************************** Powered by bboysoul Email: bboysoulcn@gmail.com Hostname: bboysoul-k8s-master Virtualization is not supported Cpu model: Common KVMprocessor Memory: 3789 M Swap: 0 M Kernel version: CentOS Linux release 7.6.1810 (Core) ********************************** 1) install_software 5) set_hostname 9) install_ohmyzsh 2) install_python 6) close_selinux 10) add_user 3) set_static_ip 7) install_docker 11) exit 4) close_firewalld 8) change_swap 12) help:
選擇第一項安裝基礎軟件,選擇第四項關閉firewalld,選擇第五項設置主機名,個人主機名是下面兩個docker
選擇第六項關閉selinux,選擇第七項安裝docker,選擇第九項安裝oh my zshjson
關閉swapvim
swapoff -a
centos
以後修改docker的倉庫地址,編輯下面這個文件api
vim /etc/docker/daemon.json
加入
{ "registry-mirrors": [ "https://docker.mirrors.ustc.edu.cn" ] }
重啓docker
一樣的兩臺機器都要操做
添加軟件源
vim /etc/yum.repos.d/kubernetes.repo
加入
[kubernetes] name=Kubernetes baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/ enabled=1 gpgcheck=1 repo_gpgcheck=1 gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
安裝
yum install kubeadm-1.10.13-0.x86_64 kubelet-1.10.13-0.x86_64 kubectl-1.10.13-0.x86_64
讓kubelet開機啓動
systemctl enable kubelet
啓動kubelet
systemctl start kubelet
發現kubelet啓動不起來
報錯
"systemed" is different from docker cgroup driver: "cgroupfs"
因而
vim /etc/systemd/system/kubelet.service.d/10-kubeadm.conf
修改
Environment="KUBELET_CGROUP_ARGS=--cgroup-driver=systemed"
爲 Environment="KUBELET_CGROUP_ARGS=--cgroup-driver=cgroupfs"
另一個節點也要這麼作
輸入下面的命令啓動master節點
kubeadm init --kubernetes-version stable-1.10 --apiserver-advertise-address 10.10.10.120 --pod-network-cidr=10.244.0.0/16
報錯
[ERROR SystemVerification]: unsupported docker version: 18.09.3
說docker版本不支持,直接忽略
kubeadm init --kubernetes-version stable-1.10 --apiserver-advertise-address 10.10.10.120 --pod-network-cidr=10.244.0.0/16 --ignore-preflight-errors=all
最後顯示
Your Kubernetes master has initialized successfully! To start using your cluster, you need to run the following as a regular user: mkdir -p $HOME/.kube sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config sudo chown $(id -u):$(id -g) $HOME/.kube/config You should now deploy a pod network to the cluster. Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at: https://kubernetes.io/docs/concepts/cluster-administration/addons/ You can now join any number of machines by running the following on each node as root: kubeadm join 10.10.10.120:6443 --token xv3h2w.x1mwfesew7jcn07b --discovery-token-ca-cert-hash sha256:16fce397d457f1fcbdfc04031fbea686722dbf9c4a5b356a06ff2d3b955528d0
說明成功
直接使用下面命令在work節點添加就好
kubeadm join 10.10.10.120:6443 --token xv3h2w.x1mwfesew7jcn07b --discovery-token-ca-cert-hash sha256:16fce397d457f1fcbdfc04031fbea686722dbf9c4a5b356a06ff2d3b955528d0 --ignore-preflight-errors=all
以後在master節點執行
mkdir -p $HOME/.kube sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config sudo chown $(id -u):$(id -g) $HOME/.kube/config
kubectl get node
你會發現兩個節點都是沒有ready的,kube-dns一直在pending狀態,是由於沒有安裝flannel網絡的緣故
➜ ~ kubectl get node NAME STATUS ROLES AGE VERSION bboysoul-k8s-master NotReady master 12m v1.10.13 bboysoul-k8s-slave1 NotReady <none> 3m v1.10.13
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/v0.10.0/Documentation/kube-flannel.yml
完成以後等幾分鐘執行
kubectl get node
你就會發現全部的節點都已經ready了
建立用戶
vim ServiceAccount.yaml
apiVersion: v1 kind: ServiceAccount metadata: name: bboysoul namespace: kube-system
給用戶綁定權限 vim ClusterRoleBinding.yaml
apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata: name: bboysoul roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole name: cluster-admin subjects: - kind: ServiceAccount name: bboysoul namespace: kube-system
以後應用執行上面的操做
kubectl apply -f ServiceAccount.yaml
kubectl apply -f ClusterRoleBinding.yaml
接着查看用戶的token
kubectl -n kube-system describe secret $(kubectl -n kube-system get secret | grep bboysoul | awk '{print $1}')
安裝
kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v1.10.1/src/deploy/recommended/kubernetes-dashboard.yaml
修改dashboard的service類型爲nodeport
kubectl -n kube-system edit service kubernetes-dashboard
把spec下
type: ClusterIP
改成
type: NodePort
查看分配的端口
kubectl get svc -n kube-system
以後使用https訪問
https://10.10.10.120:31930
接着咱們使用上面建立的用戶的token登陸就行了
關於國內網絡環境什麼的,這個我就不說了,拉取鏡像你能夠在國內各個鏡像源裏面拉,實在不會能夠問我,我由於是路由器上外網的,因此就不存在這些噁心的問題,還有k8s的更新實在是太快了,好久以前我就寫了搭建1.12版本的,後來由於工做忙,一直沒有出來,當我再想寫的時候出了1.13,當我想完善1.13安裝的時候,版本又更新了,無奈,找一個最穩定的版本玩玩算了。
歡迎關注Bboysoul的博客www.bboysoul.com
Have Fun