三台虚拟机搭建k8s集群

1.同步ntp时间,在每台上执行 ntpdate -u cn.pool.ntp.org

2.报错:docker-ce-cli conflicts with 2:docker-1.13.1-94.gitb2f74b2.el7.centos.x86_64

   因为已经安装过docker,所以先卸载掉,

   yum list installed | grep docker

  yum remove -y docker-ce.x86_64 0:18.03.0.ce-1.el7.centos

  rm -rf /var/lib/docker

3.遇到的问题,主节点的etcd可以启动,但是和node节点组不成集群,原因是docker已经安装,把主节点docker和etcd卸载,

然后重新装etcd和docker,配置后,即可组成集群

注意,先停掉三台上的etcd,清理var/lib/etcd/default内容,然后启动

4.kubernetes参考

https://blog.csdn.net/bobpen/article/details/78958675

5.其中3配置etcd会失败,参考

https://blog.csdn.net/u010039418/article/details/80993467

 

etcd指令

vi /etc/etcd/etcd.conf

systemctl stop etcd.service

cd /var/lib/etcd/

systemctl start etcd.service
etcdctl cluster-health

 

k8s正常安装起参考文档

https://blog.51cto.com/2168836/2106963?utm_source=oschina-app

https://blog.51cto.com/goome/2155643?utm_source=oschina-app

https://blog.51cto.com/10950710/2131803

按照上面搭建好环境启动镜像启动不起来

https://blog.csdn.net/weixin_37480442/article/details/81949217

以上安装的k8s版本太低,运行其他镜像的时候可能出现其他问题。

下面使用kubeadm安装高版本的k8s

https://blog.csdn.net/cdbdqn001/article/details/88183777

https://blog.csdn.net/gui951753/article/details/83316976

镜像下载方式

https://blog.csdn.net/liukuan73/article/details/83090350

折腾了一周安装不起,原来是内存不足的原因,master分配了1G,报错kubelet启动不起来,后来分配了2G就正常了

error: the server doesn't have a resource type "nodes"
将/etc/kubenetes/admin.conf的内容copy一份到~/.kube/config文件里,config文件需要自己建

coredns容器重启解决:

https://stackoverflow.com/questions/52645473/coredns-fails-to-run-in-kubernetes-cluster

 

certificate signed by unknown authority

解決:cd /root/.kube/
[root@k8s-master .kube]# ls
cache  config  http-cache
[root@k8s-master .kube]# rm -rf config 
[root@k8s-master .kube]# cp /etc/kubernetes/admin.conf .
[root@k8s-master .kube]# mv admin.conf config

 

重啓與問題

1.重啓k8s
kubeadm reset
systemctl stop kubelet
systemctl stop docker
rm -rf /var/lib/cni/
rm -rf /var/lib/kubelet/*
rm -rf /etc/cni/
ifconfig cni0 down
ifconfig flannel.1 down
ifconfig docker0 down
ip link delete cni0
ip link delete flannel.1
systemctl start docker

安装步骤

1.安装docker(指定版本安装)

sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
um list docker-ce --showduplicates | sort -r
sudo yum install -y docker-ce-17.03.2.ce-1.el7.centos 

参考https://www.cnblogs.com/harlanzhang/p/9965534.html

2.安装k8s基础

sudo yum install -y kubeadm-1.12.0 kubectl-1.12.0 --disableexcludes=kubernetes
yum install -y kubernetes-cni-0.6.0

3.基础镜像下载

运行脚本

#!/bin/bash
images=(kube-proxy:v1.12.0 kube-scheduler:v1.12.0 kube-controller-manager:v1.12.0 kube-apiserver:v1.12.0 etcd:3.2.24 pause:3.1 coredns:1.2.2)
for imageName in ${images[@]} ; do
  docker pull anjia0532/google-containers.$imageName
  docker tag anjia0532/google-containers.$imageName k8s.gcr.io/$imageName
  docker rmi anjia0532/google-containers.$imageName
done
参考https://blog.csdn.net/liukuan73/article/details/83090350

2.sudo kubeadm init --apiserver-advertise-address=192.168.169.128 --pod-network-cidr=192.168.0.0/16 --service-cidr=10.233.0.0/16 --kubernetes-version=v1.12.0
3.cp /etc/kubenetes/admin.conf /root/.kube/
  mv admin.conf config
4.安裝網絡

docker pull jmgao1983/flannel:v0.10.0-amd64
docker tag jmgao1983/flannel:v0.10.0-amd64 quay.io/coreos/flannel:v0.10.0-amd64
或者
docker pull quay.io/coreos/flannel:v0.10.0-amd64
 
wget https://raw.githubusercontent.com/coreos/flannel/v0.10.0/Documentation/kube-flannel.yml
修改其中net-conf.json中的Network参数使其与kubeadm init时指定的--pod-network-cidr保持一致
这里v0.10.0版有一个bug,需要为启动flannel的daemonset添加toleration,以允许在尚未Ready的节点上部署flannel pod:
      tolerations:
      - key: node-role.kubernetes.io/master
        operator: Exists
        effect: NoSchedule
      #添加下面这个toleration
      - key: node.kubernetes.io/not-ready
        operator: Exists
        effect: NoSchedule
kubectl apply -f kube-flannel.yml

5.檢查pod
kubectl get pods -n kube-system
kubectl get pods --all-namespaces

6.檢查到coredns報錯
  查看pod報錯日志 : kubectl logs coredns-68fb79bcf6-4mjsj -n kube-system
7.解決coredns
 參考https://blog.51cto.com/355665/2178181
  解決是備份/etc/resolv.conf
  然後刪掉 原來的/etc/resolv.conf
  修改備份文件中nameserver的地址為本機ip,然後copy到原目錄下。
  刪除coredns的pod kubectl delete pod coredns-576cbf47c7-v46rv -n kube-system
  會自動重建,查看狀態發現正確了

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐