当前位置:   article > 正文

kubeadm 部署K8S集群_kubeadm init --image-repository

kubeadm init --image-repository

k8s几个概念

kubeadm:用于k8s集群部署

kubelet:Master在Node节点上的Agent,管理本机运行容器的生命周期

Kubesphere与Rancher:k8s集群管理平台

1.虚拟机准备

windows 下通过vm virtualbox 安装3台虚拟机(1个master,2个node)

cpu:2核

网络连接设置为桥接网卡,配置好网络后重启服务

关闭防火墙:

systemctl stop firewalld
systemctl disable firewalld

关闭swap:

swapoff -a # 临时关闭
sed -ri 's/.*swap.*/#&/' /etc/fstab  #永久关闭

2.xshell 进入master,安装docker

wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo -O /etc/yum.repos.d/docker-ce.repo
yum -y install docker-ce-18.06.1.ce-3.el7
systemctl enable docker && systemctl start docker
docker --version

3.添加kubernetes YUM软件源

cat > /etc/yum.repos.d/kubernetes.repo << EOF
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=0
repo_gpgcheck=0
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF

4. 安装kubeadm,kubelet和kubectl

yum install -y kubelet-1.15.0 kubeadm-1.15.0 kubectl-1.15.0
systemctl enable kubelet

5.部署Kubernetes Master[master上执行]

kubeadm init --apiserver-advertise-address=172.16.1.xx --image-repository registry.aliyuncs.com/google_containers --kubernetes-version v1.15.0 --service-cidr=10.1.0.0/16 --pod-network-cidr=10.244.0.0/16

5.1设定master错误

    [ERROR FileContent--proc-sys-net-bridge-bridge-nf-call-iptables]: /proc/sys/net/bridge/bridge-nf-call-iptables contents are not set to 1

---解决:按提示设定为1

echo "1" >/proc/sys/net/ipv4/ip_forward
echo "1" >/proc/sys/net/bridge/bridge-nf-call-iptables


5.2 Kubeadm init 安装镜像卡住,采用如下脚本拉取镜像

  1. # kubeadm config images list --kubernetes-version v1.13.0 # 看下该版本下的镜像名
  2. # 拉取镜像
  3. docker pull mirrorgooglecontainers/kube-apiserver:v1.13.0
  4. docker pull mirrorgooglecontainers/kube-controller-manager:v1.13.0
  5. docker pull mirrorgooglecontainers/kube-scheduler:v1.13.0
  6. docker pull mirrorgooglecontainers/kube-proxy:v1.13.0
  7. docker pull mirrorgooglecontainers/pause:3.1
  8. docker pull mirrorgooglecontainers/etcd:3.2.24
  9. docker pull coredns/coredns:1.2.6
  10. # 重命名镜像标签
  11. docker tag docker.io/mirrorgooglecontainers/kube-proxy:v1.13.0 k8s.gcr.io/kube-proxy:v1.13.0
  12. docker tag docker.io/mirrorgooglecontainers/kube-scheduler:v1.13.0 k8s.gcr.io/kube-scheduler:v1.13.0
  13. docker tag docker.io/mirrorgooglecontainers/kube-apiserver:v1.13.0 k8s.gcr.io/kube-apiserver:v1.13.0
  14. docker tag docker.io/mirrorgooglecontainers/kube-controller-manager:v1.13.0 k8s.gcr.io/kube-controller-manager:v1.13.0
  15. docker tag docker.io/mirrorgooglecontainers/etcd:3.2.24 k8s.gcr.io/etcd:3.2.24
  16. docker tag docker.io/mirrorgooglecontainers/pause:3.1 k8s.gcr.io/pause:3.1
  17. docker tag docker.io/coredns/coredns:1.2.6 k8s.gcr.io/coredns:1.2.6
  18. # 删除旧镜像
  19. docker rmi docker.io/mirrorgooglecontainers/kube-proxy:v1.13.0
  20. docker rmi docker.io/mirrorgooglecontainers/kube-scheduler:v1.13.0
  21. docker rmi docker.io/mirrorgooglecontainers/kube-apiserver:v1.13.0
  22. docker rmi docker.io/mirrorgooglecontainers/kube-controller-manager:v1.13.0
  23. docker rmi docker.io/mirrorgooglecontainers/etcd:3.2.24
  24. docker rmi docker.io/mirrorgooglecontainers/pause:3.1
  25. docker rmi docker.io/coredns/coredns:1.2.6

6.安装Pod网络插件(CNI)

kubectl apply -fhttps://raw.githubusercontent.com/coreos/flannel/a70459be0084506e4ec919aa1c114638878db11b/Documentation/kube-flannel.yml

7. 加入Kubernetes Node

在node上安装flannel

docker pull lizhenliang/flannel:v0.11.0-amd64


kubeadm join 192.168.116.129:6443 --token iz96vy.f5ukew9geeome5is \ --discovery-token-ca-cert-hash sha256:72b689426bfc34512294c29b39ea3b2af3a94e39f62c4434f3a49f16d51a1382 

查看node

kubectl get node

8. 测试kubernetes集群

创建nginx容器

kubectlcreate deployment nginx --image=nginx

暴露对外端口

kubectl expose deployment nginx --port=80 --type=NodePort

查看nginx是否运行成功

kubectl get pod,svc

在浏览器访问。三个结点都可访问,说明集群已经搭建完成,

172.16.xx.xx:31173

9. 部署 Dashboard

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/728015
推荐阅读
相关标签
  

闽ICP备14008679号