k8s之kubeadm部署kubernetes13.1最新版本
2018年12月27日
當前最新版的kubeadm為GitVersion:“v1.13.1”
kubeadm安裝方式比二進位制方式方便的多,雖然還是beta版本,但是有許多大膽的哥們已經上綱上線了。
系統:CentOS Linux release 7.4.1708 (Core)
網路外掛:calico3.1
系統環境:
下面一個簡單的init.sh指令碼,對系統環境進行設定,192.168.226.0是我虛擬機器的網段,需要使用的請自行修改指令碼。
#!/bin/bash [ -z "$1" ] && { echo "IP not exsit..";exit 1; } cat > /etc/sysconfig/network-scripts/ifcfg-ens33 << EOF TYPE=Ethernet BOOTPROTO=static DEVICE=ens33 ONBOOT=yes IPADDR=192.168.226.${1} GATEWAY=192.168.226.2 NETMASK=255.255.255.0 DNS1=114.114.114.114 EOF /etc/init.d/network restart hostnamectl set-hostname k8s-node{$1} systemctl stop firewalld systemctl disable firewalld sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config setenforce 0 ###設定控制代碼 if [ ! -f /etc/security/limits.d/65536.conf ]; then cat >> /etc/security/limits.d/65536.conf << EOF * soft nofile 65536 * hard nofile 65536 EOF fi ulimit -n 65536 ###關閉swap swapoff -a sed -i '/swap/s/^/#&/g' /etc/fstab ###新增kubeadm源 rm -f /etc/yum.repos.d/kubernetes.repo cat <<EOF > /etc/yum.repos.d/kubernetes.repo [kubernetes] name=Kubernetes baseurl=http://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64 enabled=1 gpgcheck=0 repo_gpgcheck=0 gpgkey=http://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg http://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg EOF yum makecache yum install net-tools epel-release ipvsadm iptables curl wget vim -y yum install kubeadm-1.13.1-0 kubectl-1.13.1-0 kubelet-1.13.1-0 -y
我用vm虛擬機器模板建立兩臺虛擬機器
IP為:
192.168.226.151
192.168.226.152
相對應執行:
sh init.sh 151
sh init.sh 152
安裝docker:
安裝包下載:
https://blog.csdn.net/Arno_e/article/details/85229497
yum localinstall xx.rpm 安裝
新增阿里雲加速(這個可以自己登入阿里雲:https://cr.console.aliyun.com/cn-hangzhou/mirrors):
mkdir -p /etc/docker tee /etc/docker/daemon.json <<-'EOF' { "registry-mirrors": ["https://d1a5lj3d.mirror.aliyuncs.com"] } EOF systemctl daemon-reload systemctl restart docker
kubeadm所需的映象:
kubeadm列印所需映象
[[email protected] ~]# kubeadm config images list
k8s.gcr.io/kube-apiserver:v1.13.1
k8s.gcr.io/kube-controller-manager:v1.13.1
k8s.gcr.io/kube-scheduler:v1.13.1
k8s.gcr.io/kube-proxy:v1.13.1
k8s.gcr.io/pause:3.1
k8s.gcr.io/etcd:3.2.24
k8s.gcr.io/coredns:1.2.6
有vpn的同學可自行下載
百度雲:
連結:
提取碼:upkg
解壓calico3.1.tar.gz,匯入映象(所有節點都需要匯入):
[[email protected] calico3.1]# ls *.tar | while read line;do docker load < $line;done
[[email protected] calico3.1]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
k8s.gcr.io/kube-proxy v1.13.1 fdb321fd30a0 13 days ago 80.2MB
k8s.gcr.io/kube-controller-manager v1.13.1 26e6f1db2a52 13 days ago 146MB
k8s.gcr.io/kube-apiserver v1.13.1 40a63db91ef8 13 days ago 181MB
k8s.gcr.io/kube-scheduler v1.13.1 ab81d7360408 13 days ago 79.6MB
quay.io/calico/node v3.1.4 715f56d3ab67 6 weeks ago 241MB
quay.io/calico/cni v3.1.4 e454b0fb4bfd 6 weeks ago 69.4MB
quay.io/calico/kube-controllers v3.1.4 b8cb3e057df7 6 weeks ago 55.5MB
k8s.gcr.io/coredns 1.2.6 f59dcacceff4 7 weeks ago 40MB
k8s.gcr.io/etcd 3.2.24 3cab8e1b9802 3 months ago 220MB
k8s.gcr.io/pause 3.1 da86e6ba6ca1 12 months ago 742kB
quay.io/coreos/etcd v3.1.10 47bb9dd99916 17 months ago 34.6MB
叢集初始化:
[[email protected] calico3.1]# kubeadm init --pod-network-cidr=192.168.0.0/16
You can now join any number of machines by running the following on each node
as root:
kubeadm join 192.168.226.151:6443 --token 06q06g.tr7s9msx9knpgrhw --discovery-token-ca-cert-hash sha256:c826c91c9038d67655d88fa4f64b9777d0ed7357567614d3613f98c8e2522e8f
出現上面提示說明成功了。
注意192.168.0.0/16是calico 定義的網段,網路外掛不同,這個有可能會不一樣
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
建立配置檔案
安裝calico外掛(calico官方文件):
kubectl apply -f \
https://docs.projectcalico.org/v3.1/getting-started/kubernetes/installation/hosted/kubeadm/1.7/calico.yaml
加入node節點
[email protected] calico3.1]# systemctl start docker
[email protected] calico3.1]#
[email protected] calico3.1]# kubeadm join 192.168.226.151:6443 --token 06q06g.tr7s9msx9knpgrhw --discovery-token-ca-cert-hash sha256:c826c91c9038d67655d88fa4f64b9777d0ed7357567614d3613f98c8e2522e8f
join 後面的引數為master節點kubeadm init 成功後的輸出提示。
檢查:
[email protected] calico3.1]# kubectl get nodes
NAME STATUS ROLES AGE VERSION
k8s-node151 Ready master 7m52s v1.13.1
k8s-node152 Ready <none> 5m35s v1.13.1
[[email protected] calico3.1]# kubectl get pods --all-namespaces
NAMESPACE NAME READY STATUS RESTARTS AGE
kube-system calico-etcd-zlnhh 1/1 Running 0 57m
kube-system calico-kube-controllers-7fdb769cd8-z9mrv 1/1 Running 0 57m
kube-system calico-node-dvz7q 2/2 Running 1 56m
kube-system calico-node-g7xq9 2/2 Running 1 57m
kube-system coredns-86c58d9df4-49cdw 1/1 Running 0 58m
kube-system coredns-86c58d9df4-l8r8c 1/1 Running 0 58m
kube-system etcd-k8s-node151 1/1 Running 0 57m
kube-system kube-apiserver-k8s-node151 1/1 Running 0 57m
kube-system kube-controller-manager-k8s-node151 1/1 Running 0 57m
kube-system kube-proxy-668l7 1/1 Running 0 56m
kube-system kube-proxy-x5q8x 1/1 Running 0 58m
kube-system kube-scheduler-k8s-node151 1/1 Running 0 57m
如上,表示部署成功。
有一點需要注意的是,網路外掛需要在node節點新增之前就要安裝,否則calico外掛的節點會被分配在不同的節點上,導致元件之間無法通訊。