k8s之kubeadm部署kubernetes13.1最新版本

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/Arno_e/article/details/85283543

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打印所需镜像
[root@k8s-node151 ~]# 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的同学可自行下载
百度云:
链接:https://pan.baidu.com/s/1gY0eJcTraUMg_d9hK59Hkg
提取码:upkg
解压calico3.1.tar.gz,导入镜像(所有节点都需要导入):

[root@k8s-node151 calico3.1]# ls *.tar | while read line;do docker load < $line;done
[root@k8s-node151 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

集群初始化:

    [root@k8s-node151 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节点

root@k8s-node152 calico3.1]# systemctl start  docker
root@k8s-node152 calico3.1]# 
root@k8s-node152 calico3.1]# kubeadm join 192.168.226.151:6443 --token 06q06g.tr7s9msx9knpgrhw --discovery-token-ca-cert-hash sha256:c826c91c9038d67655d88fa4f64b9777d0ed7357567614d3613f98c8e2522e8f

join 后面的参数为master节点kubeadm init 成功后的输出提示。

检查:

root@k8s-node151 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

[root@k8s-node151 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插件的节点会被分配在不同的节点上,导致组件之间无法通讯。
有疑问可以一起探讨

展开阅读全文

没有更多推荐了,返回首页