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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM