kubeadm 安装kubernetes1.6.2

准备工作

安装依赖

 yum install -y wget vim net-tools epel-release

修改内核参数

cat <<EOF >  /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sysctl --system

配置K8S源

## 配置k8s源
cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=0
EOF
 
## 重建yum缓存
yum clean all
yum makecache fast
yum -y update

安装docker

yum -y install yum-utils device-mapper-persistent-data lvm2
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
#查看版本
yum list docker-ce --showduplicates |sort -r   
#安装指定版本
yum install -y docker-ce-18.09.9-3.el7
systemctl enable docker
systemctl start docker
cat > /etc/docker/daemon.json <<EOF
{
    "registry-mirrors": ["https://z34wtdhg.mirror.aliyuncs.com"],
    "insecure-registries":["harbor.suixingpay.com","bh-harbor.suixingpay.com"],
    "storage-driver": "overlay2",
    "storage-opts": ["overlay2.override_kernel_check=true"]
}
{
"log-driver": "json-file",
"log-opts": {
    "max-size": "100m",
    "max-file": "3"
    }
}
EOF
systemctl restart docker

安装kubernetes

下载kubeadm,kubelet

yum install -y kubeadm kubelet

初始化kubeadm

这里不直接初始化,因为国内用户不能直接拉取相关的镜像,所以这里想查看需要的镜像版本

kubeadm config images list

根据需要的版本,直接拉取国内镜像,并修改tag

$ vim kubeadm.sh
 
#!/bin/bash
## 使用如下脚本下载国内镜像,并修改tag为google的tag
set -e
 
KUBE_VERSION=v1.16.2
KUBE_PAUSE_VERSION=3.1
ETCD_VERSION=3.3.15-0
CORE_DNS_VERSION=1.6.2
 
GCR_URL=k8s.gcr.io
ALIYUN_URL=registry.cn-hangzhou.aliyuncs.com/google_containers
 
images=(kube-proxy:${KUBE_VERSION}
kube-scheduler:${KUBE_VERSION}
kube-controller-manager:${KUBE_VERSION}
kube-apiserver:${KUBE_VERSION}
pause:${KUBE_PAUSE_VERSION}
etcd:${ETCD_VERSION}
coredns:${CORE_DNS_VERSION})
 
for imageName in ${images[@]} ; do
  docker pull $ALIYUN_URL/$imageName
  docker tag  $ALIYUN_URL/$imageName $GCR_URL/$imageName
  docker rmi $ALIYUN_URL/$imageName
done

运行脚本,拉取镜像

sh ./kubeadm.sh

master节点安装

sudo kubeadm init \
 --apiserver-advertise-address 10.10.3.111 \
 --kubernetes-version=v1.16.2 \
 --pod-network-cidr=10.244.0.0/16
执行结果
.......... Your Kubernetes control
-plane 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/ Then you can join any number of worker nodes by running the following on each as root:
## 添加节点需要执行以下命令,可以使用命令 kubeadm token create --print-join-command 来获取
kubeadm join 10.10.3.111:6443 --token re24q1.7sin74aq7c0awnru \
    --discovery-token-ca-cert-hash sha256:82e68e2af70c642e7307c68505f513149c364867fd368ab0305c85ad2777f037

Node节点安装

节点中运行

kubeadm join 10.10.3.111:6443 --token re24q1.7sin74aq7c0awnru \
    --discovery-token-ca-cert-hash sha256:82e68e2af70c642e7307c68505f513149c364867fd368ab0305c85ad2777f037 \
   --ignore-preflight-errors=all 

安装flanneld

master节点上执行如下命令:

mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config

下载flannel配置文件

wget https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml

因为kube-flannel.yml文件中使用的镜像为quay.io的,国内无法拉取,所以同样的先从国内源上下载,再修改tag,脚本如下

$  vim flanneld.sh
 
#!/bin/bash
set -e
 
FLANNEL_VERSION=v0.11.0
 
# 在这里修改源
QUAY_URL=quay.io/coreos
QINIU_URL=quay-mirror.qiniu.com/coreos
 
images=(flannel:${FLANNEL_VERSION}-amd64
flannel:${FLANNEL_VERSION}-arm64
flannel:${FLANNEL_VERSION}-arm
flannel:${FLANNEL_VERSION}-ppc64le
flannel:${FLANNEL_VERSION}-s390x)
 
for imageName in ${images[@]} ; do
  docker pull $QINIU_URL/$imageName
  docker tag  $QINIU_URL/$imageName $QUAY_URL/$imageName
  docker rmi $QINIU_URL/$imageName
done

运行脚本,这个脚本需要在每个节点上执行

sh flanneld.sh

安装flanneld

kubectl apply -f kube-flannel.yml

查看是否正常

$  kubectl get pod -n kube-system
NAME                                 READY   STATUS    RESTARTS   AGE
coredns-5644d7b6d9-g7hnf             1/1     Running   0          12m
coredns-5644d7b6d9-ll2vr             1/1     Running   0          12m
etcd-k8s-master                      1/1     Running   0          11m
kube-apiserver-k8s-master            1/1     Running   0          11m
kube-controller-manager-k8s-master   1/1     Running   0          11m
kube-flannel-ds-amd64-7fqhp          1/1     Running   0          30s
kube-flannel-ds-amd64-t87t6          1/1     Running   0          30s
kube-flannel-ds-amd64-t8d6f          1/1     Running   0          30s
kube-proxy-dv7fl                     1/1     Running   0          9m29s
kube-proxy-gbfvx                     1/1     Running   0          8m37s
kube-proxy-ndm5m                     1/1     Running   0          12m
kube-scheduler-k8s-master            1/1     Running   0          11m

查看集群是否正常

$ kubectl get nodes
NAME         STATUS   ROLES    AGE     VERSION
k8s-master   Ready    master   13m     v1.16.2
k8s-node01   Ready    <none>   9m55s   v1.16.2
k8s-node02   Ready    <none>   9m3s    v1.16.2

 

posted @ 2019-11-12 13:34  大胖猴  阅读(827)  评论(0编辑  收藏  举报