小白安装指南 使用kubeadm安装集群 kubernetes v1.9.6

前提:

环境centeos 7

可以上外网,因为所有的工具都是通过外网获取的

在master和node上执行

解决镜像慢的问题

*根据具体情况进行修改


sudo mkdir -p /etc/docker

sudo tee /etc/docker/daemon.json <<-'EOF'

{

  "registry-mirrors": ["https://*.mirror.aliyuncs.com"]

}

EOF

sudo systemctl daemon-reload

sudo systemctl restart docker

master节点执行

配置docker yum源(自行配置)

这个repo主要用来装docker

yum install -y docker

systemctl start docker

配置kubernetes的yum源

ali_kube.repo

[kubernetes_ali]

name=Kubernetes

baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64

enabled=1

gpgcheck=0

这个repo用来安装kubeadm和kubelet

目前是v1.9.6的kubeadm

可以使用 kubeadm version 查看版本

yum install -y kubeadm kubelet

(根据版本自己拼装yum install -y kubeadm-1.9.6-0.x86_64 kubelet-1.9.6-0.x86_64)

预先下载相关的镜像

如果不事先下好,会默认到国外的网站去pulldocker镜像,这样就会失败的

下载好之后还要把docker镜像名打个tag,不然kubeadm是不识别的

docker_pull 文件

#

docker pull registry.cn-shenzhen.aliyuncs.com/eaglering/pause-amd64:3.0

docker pull registry.cn-shenzhen.aliyuncs.com/eaglering/kube-apiserver-amd64:v1.9.6

docker pull registry.cn-shenzhen.aliyuncs.com/eaglering/kube-controller-manager-amd64:v1.9.6

docker pull registry.cn-shenzhen.aliyuncs.com/eaglering/kube-scheduler-amd64:v1.9.6

docker pull registry.cn-shenzhen.aliyuncs.com/eaglering/kube-proxy-amd64:v1.9.6

#docker pull registry.cn-hangzhou.aliyuncs.com/capfgd/etcd-amd64:3.1.10

docker pull registry.cn-hangzhou.aliyuncs.com/capfgd/etcd-amd64:3.1.11

docker pull registry.cn-shenzhen.aliyuncs.com/eaglering/k8s-dns-sidecar-amd64:1.14.7

docker pull registry.cn-shenzhen.aliyuncs.com/eaglering/k8s-dns-kube-dns-amd64:1.14.7

docker pull registry.cn-shenzhen.aliyuncs.com/eaglering/k8s-dns-dnsmasq-nanny-amd64:1.14.7

docker tag registry.cn-shenzhen.aliyuncs.com/eaglering/pause-amd64:3.0 k8s.gcr.io/pause-amd64:3.0

docker tag registry.cn-shenzhen.aliyuncs.com/eaglering/kube-apiserver-amd64:v1.9.6 k8s.gcr.io/kube-apiserver-amd64:v1.9.6

docker tag registry.cn-shenzhen.aliyuncs.com/eaglering/kube-controller-manager-amd64:v1.9.6 k8s.gcr.io/kube-controller-manager-amd64:v1.9.6

docker tag registry.cn-shenzhen.aliyuncs.com/eaglering/kube-scheduler-amd64:v1.9.6 k8s.gcr.io/kube-scheduler-amd64:v1.9.6

docker tag registry.cn-shenzhen.aliyuncs.com/eaglering/kube-proxy-amd64:v1.9.6 k8s.gcr.io/kube-proxy-amd64:v1.9.6

#docker tag registry.cn-hangzhou.aliyuncs.com/capfgd/etcd-amd64:3.1.10 k8s.gcr.io/etcd-amd64:3.1.10

docker tag registry.cn-hangzhou.aliyuncs.com/capfgd/etcd-amd64:3.1.11 k8s.gcr.io/etcd-amd64:3.1.11

docker tag registry.cn-shenzhen.aliyuncs.com/eaglering/k8s-dns-sidecar-amd64:1.14.7 k8s.gcr.io/k8s-dns-sidecar-amd64:1.14.7

docker tag registry.cn-shenzhen.aliyuncs.com/eaglering/k8s-dns-kube-dns-amd64:1.14.7 k8s.gcr.io/k8s-dns-kube-dns-amd64:1.14.7

docker tag registry.cn-shenzhen.aliyuncs.com/eaglering/k8s-dns-dnsmasq-nanny-amd64:1.14.7 k8s.gcr.io/k8s-dns-dnsmasq-nanny-amd64:1.14.7

docker tag registry.cn-shenzhen.aliyuncs.com/eaglering/pause-amd64:3.0 gcr.io/google_containers/pause-amd64:3.0

docker tag registry.cn-shenzhen.aliyuncs.com/eaglering/kube-apiserver-amd64:v1.9.6 gcr.io/google_containers/kube-apiserver-amd64:v1.9.6

docker tag registry.cn-shenzhen.aliyuncs.com/eaglering/kube-controller-manager-amd64:v1.9.6 gcr.io/google_containers/kube-controller-manager-amd64:v1.9.6

docker tag registry.cn-shenzhen.aliyuncs.com/eaglering/kube-scheduler-amd64:v1.9.6 gcr.io/google_containers/kube-scheduler-amd64:v1.9.6

docker tag registry.cn-shenzhen.aliyuncs.com/eaglering/kube-proxy-amd64:v1.9.6 gcr.io/google_containers/kube-proxy-amd64:v1.9.6

#docker tag registry.cn-hangzhou.aliyuncs.com/capfgd/etcd-amd64:3.1.10 gcr.io/google_containers/etcd-amd64:3.1.10

docker tag registry.cn-hangzhou.aliyuncs.com/capfgd/etcd-amd64:3.1.11 gcr.io/google_containers/etcd-amd64:3.1.11

docker tag registry.cn-shenzhen.aliyuncs.com/eaglering/k8s-dns-sidecar-amd64:1.14.7 gcr.io/google_containers/k8s-dns-sidecar-amd64:1.14.7

docker tag registry.cn-shenzhen.aliyuncs.com/eaglering/k8s-dns-kube-dns-amd64:1.14.7 gcr.io/google_containers/k8s-dns-kube-dns-amd64:1.14.7

docker tag registry.cn-shenzhen.aliyuncs.com/eaglering/k8s-dns-dnsmasq-nanny-amd64:1.14.7 gcr.io/google_containers/k8s-dns-dnsmasq-nanny-amd64:1.14.7

kubeadm init --kubernetes-version=1.9.6

使用这个命令初始化kubernetes集群的master节点

安装成功之后执行

useradd k8s

mkdir -p /home/k8s/.kube

cp -i /etc/kubernetes/admin.conf /home/k8s/.kube/config

vim /home/k8s/.kube/config

ll /home/k8s/.kube/config

chown k8s:k8s /home/k8s/.kube/config

ll /home/k8s/.kube/config

遇到的问题

1.如果docker镜像手动拉取太慢,可以使用阿里云的镜像加速,网站https://cr.console.aliyun.com

并且可以在这里搜索可用的镜像以及对应的版本

将自己私有的加速网址加到docker的启动参数中,OPTIONS='--registry-mirror=http://*****'

2.使用kubeadm 初始化集群的时候会出现很多的错误,这个时候需要观察日志来排查到底是哪里出了问题。需要观察的日志是kubelet和docker的,默认是在/var/log/message文件中

tail -f /var/log/messages | grep kubelet

tail -f /var/log/messages | grep docker

如果kubelet日志碰到 network plugin is not ready: cni config uninitialized

将/etc/systemd/system/kubelet.service.d/10-kubeadm.conf中$KUBELET_NETWORK_ARGS注释

刚开始kubelet会出现类似

Mar 28 15:42:02 cloudboot kubelet: E0328 15:42:02.796341 15751 reflector.go:205] k8s.io/kubernetes/pkg/kubelet/kubelet.go:480: Failed to list *v1.Node: Get https://172.16.3.144:6443/api/v1/nodes?fieldSelector=metadata.name%3Dcloudboot&limit=500&resourceVersion=0: dial tcp 172.16.3.144:6443: getsockopt: connection refused

这个属于正常的,之后会消失

3.不同kubeadm找的docker镜像名和版本都是不一样的,就连官网说的那个版本https://kubernetes.io/docs/reference/setup-tools/kubeadm/kubeadm-init/#running-kubeadm-without-an-internet-connection 里面的名称和版本都有错的,以实际日志中给出的信息为准

工作节点

Ubuntu

apt install curl

apt-get install -y apt-transport-https

apt install docker.io

curl -s[https://mirrors.aliyun.com/kubernetes/apt/doc/](https://mirrors.aliyun.com/kubernetes/apt/doc/)apt-key.gpg | apt-key add -

cat < /etc/apt/sources.list.d/kubernetes.list

debhttps://mirrors.aliyun.com/kubernetes/apt/kubernetes-xenial main

EOF

apt-get update

apt-get install -y kubelet kubeadm kubectl kubernetes-cni

(指定版本  apt-get install -y kubelet=1.9.6-00 kubeadm=1.9.6-00 kubectl=1.9.6-00 kubernetes-cni=0.6.0-00)

systemctl start docker && systemctl enable docker

redhat

见master节点yum仓库的配置

如果为了上网而执行了http_proxy或https_proxy 加入节点前一定要unset这些代理不然会出现连接forbidden的问题

为docker设置代理,不用在系统变量里设置

mkdir /etc/systemd/system/docker.service.d

 cat /etc/systemd/system/docker.service.d/http-proxy.conf

[Service]

Environment="HTTP_PROXY=http://172.16.3.11:3128"

Environment="HTTPS_PROXY=http://172.16.3.11:3128"

systemctl daemon-reload

systemctl restart docker

加入节点

kubeadm join --token 4b1a19.d0e8c2b47a36e6d7 172.16.38.210:6443 --discovery-token-ca-cert-hash sha256:4beb4dc70f098f69a0fd4d85e61c9dc852ff1bd8e855a999d00ae7f87e2e54c8

上面的命令是master节点安装成功后给出的,如果是第二次加入token需要重新生成(在master节点上执行 kubeadm token create)

替换上面的token

su - k8s

kubectl get nodes

NAME STATUS ROLES AGE VERSION

cloudboot Ready master 2h v1.9.6

ubuntu-kvm NotReady 5m v1.9.6

Ubuntu系统的日志在

tailf /var/log/syslog | grep kubelet

通过日志可以看到还是需要装一些东西的(可能会需要disable network args)

docker pull registry.cn-shenzhen.aliyuncs.com/eaglering/pause-amd64:3.0

docker tag registry.cn-shenzhen.aliyuncs.com/eaglering/pause-amd64:3.0 gcr.io/google_containers/pause-amd64:3.0

docker pull registry.cn-shenzhen.aliyuncs.com/eaglering/kube-proxy-amd64:v1.9.6

docker tag registry.cn-shenzhen.aliyuncs.com/eaglering/kube-proxy-amd64:v1.9.6 gcr.io/google_containers/kube-proxy-amd64:v1.9.6

在master节点上执行 (只执行一次)

kubectl apply -f "https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d '\n')"

当前pods的运行状态

kubectl get pods --all-namespaces

需要都运行正常(running)

kubectl --namespace=kube-system describe pod weave-net-x7k59

查看具体哪个pods的出错信息

因为weave也需要pull镜像,并且在master和node上都装不上,手动拉取吧

weaveworks/weave-kube:2.2.1

weaveworks/weave-npc:2.2.1

docker pull weaveworks/weave-kube:2.2.1

docker pull weaveworks/weave-npc:2.2.1

如果需要清空kubernetes安装环境

在每个节点(master和node)上kubeadm reset重新安装,master节点kubeadm init

你可能感兴趣的:(小白安装指南 使用kubeadm安装集群 kubernetes v1.9.6)