美文网首页
kubeadm安装

kubeadm安装

作者: F7bonacci | 来源:发表于2019-03-17 22:23 被阅读0次

    kubeadm安装
    安装环境(vm6.5下虚拟机3台,centos 7.4):
    master:10.20.0.191
    Node1:10.20.0.192
    Node2:10.20.0.193

    1.安装虚拟机,配置网络接口;
    2.修改主机名
    hostnamectl set-hostname k8s-master
    3.安装常用工具

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

    4.配置yum源环境(是用阿里云镜像)

    docker-ce
    /etc/yum.repos.d目录下
    wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
    kubernetes
    /etc/yum.repos.d目录下
    vim kubenetes.repo
    [root@k8s-master yum.repos.d]# cat kubenetes.repo 
    [kubernetes]
    name=Kubernetes Repo
    baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
    gpgcheck=1    #开启gpg校验
    gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg
    enabled=1
    
     yum repolist 检测yum源列表
    

    5.gpg校验配置

    下载校验文件
     wget https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
     wget https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg
    导入校验文件
     rpm --import rpm-package-key.gpg 
     rpm --import yum-key.gpg 
    

    6.关闭firewall,修改内核参数

    systemctl disable firewalld
    systemctl stop firewalld
    vim /etc/sysctl.d/k8s.conf
    添加如下内容
    net.bridge.bridge-nf-call-ip6tables = 1
    net.bridge.bridge-nf-call-iptables = 1
    net.ipv4.ip_forward = 1
    执行命令生效
    modprobe br_netfilter
    sysctl -p /etc/sysctl.d/k8s.conf
    禁用节点上的swap
    swapoff -a 
    sysctl -p
    vim /ets/fstab   #去除该文件中关于swap那行
    

    7.安装docker-ce,kubelet组件

    master节点安装
    yum install docker-ce kubelet kubeadm kubectl 
    node节点安装
    yum install docker-ce kubelet kubeadm 
    

    8.启动docker,kubelet

    • 编辑kubelet的配置文件/etc/sysconfig/kubelet,设置其忽略Swap启用的状态错误,内容如下: KUBELET_EXTRA_ARGS=“—fail-swap-on=false” ,master以及node节点均需设置;
    [root@k8s-master yum.repos.d]# cat /etc/sysconfig/kubelet 
    KUBELET_EXTRA_ARGS="--fail-swap-on=false"
    
    • google的镜像仓库k8s.grc.io国内无法访问,如有代理服务器,则编辑docker.service文件,添加代理服务器
    vim /usr/lib/systemd/system/docker.service
    添加如下内容
    Environment="HTTPS_PROXY=https://[proxy-addr]:[proxy-port]/"
    保存退出,从新加载配置文件,重启docker
    systemctl daemon-reload
    systemctl restart docker
    
    • 启动docker,kubelet
    systemctl enable docker kubelet 
    systemctl start docker
    
    
    • 无代理服务,可以把k8s的软件包下载到本地安装,通过(docker load)命令加载tar包;
      9.初始化master节点,node节点
    master节点需要pull完成的相关镜像
    k8s.gcr.io/kube-proxy                            v1.13.3             98db19758ad4        2 weeks ago         80.3MB
    k8s.gcr.io/kube-apiserver                        v1.13.3             fe242e556a99        2 weeks ago         181MB
    k8s.gcr.io/kube-controller-manager               v1.13.3             0482f6400933        2 weeks ago         146MB
    k8s.gcr.io/kube-scheduler                        v1.13.3             3a6f709e97a0        2 weeks ago         79.6MB
    k8s.gcr.io/coredns                               1.2.6               f59dcacceff4        3 months ago        40MB
    k8s.gcr.io/etcd                                  3.2.24              3cab8e1b9802        5 months ago        220MB
    k8s.gcr.io/pause                                 3.1                 da86e6ba6ca1        14 months ago       742kB
    quay.io/coreos/flannel                           v0.11.0-amd64       ff281650a721        2 weeks ago         52.6MB
    
    node节点需要pull完成的相关镜像
    k8s.gcr.io/kube-proxy               v1.13.3             98db19758ad4        2 weeks ago         80.3MB
    k8s.gcr.io/pause                    3.1                 da86e6ba6ca1        14 months ago       742kB
    quay.io/coreos/flannel              v0.11.0-amd64       ff281650a721        2 weeks ago         52.6MB
    
    目前默认版本为1.13.3
    kubeadm init --help 查看启动参数 默认监听端口6443
    kubeadm init --kubernetes-version=v1.13.3 --pod-network-cidr=10.244.0.0/16 service- 
    cidr=10.96.0.0/12 --ignore-preflight-errors=Swap 
    启动完成后会显示join命令,记得保存
    根据提示完成非root用户配置
    mkdir ~/.kube 
    cp /etc/kubernetes/admin.conf ~/.kube/
    chown $(id -u):$(id -g) $HOME/.kube/config
    

    检查启动情况(nodes此时还只有master节点,未安装flannel时候状态不是ready)

    [root@k8s-master yum.repos.d]# kubectl get componentstatus
    NAME                 STATUS    MESSAGE              ERROR
    scheduler            Healthy   ok                   
    controller-manager   Healthy   ok                   
    etcd-0               Healthy   {"health": "true"}   
    [root@k8s-master yum.repos.d]# kubectl get nodes
    NAME         STATUS   ROLES    AGE    VERSION
    k8s-master   Ready    master   137m   v1.13.3
    k8s-node1    Ready    <none>   72m    v1.13.3
    k8s-node2    Ready    <none>   59m    v1.13.3
    

    10.安装flannel组件
    coredns依赖flannel组件,未安装flannel时候查看coredns的状态为prending

    [root@k8s-master yum.repos.d]# kubectl get pods -n kube-system -o wide
    NAME                                 READY   STATUS    RESTARTS   AGE    IP            NODE         NOMINATED NODE   READINESS GATES
    coredns-86c58d9df4-697md             1/1     Running   0          141m   10.244.0.2    k8s-master   <none>           <none>
    coredns-86c58d9df4-7ppx6             1/1     Running   0          141m   10.244.0.3    k8s-master   <none>           <none>
    etcd-k8s-master                      1/1     Running   0          140m   10.20.0.191   k8s-master   <none>           <none>
    kube-apiserver-k8s-master            1/1     Running   0          140m   10.20.0.191   k8s-master   <none>           <none>
    kube-controller-manager-k8s-master   1/1     Running   0          140m   10.20.0.191   k8s-master   <none>           <none>
    kube-flannel-ds-amd64-jnr54          1/1     Running   0          108m   10.20.0.191   k8s-master   <none>           <none>
    kube-flannel-ds-amd64-n9c74          1/1     Running   0          64m    10.20.0.193   k8s-node2    <none>           <none>
    kube-flannel-ds-amd64-x7tj8          1/1     Running   0          77m    10.20.0.192   k8s-node1    <none>           <none>
    kube-proxy-8cvq4                     1/1     Running   0          77m    10.20.0.192   k8s-node1    <none>           <none>
    kube-proxy-kc6bb                     1/1     Running   0          64m    10.20.0.193   k8s-node2    <none>           <none>
    kube-proxy-rcfrt                     1/1     Running   0          141m   10.20.0.191   k8s-master   <none>           <none>
    kube-scheduler-k8s-master            1/1     Running   0          141m   10.20.0.191   k8s-master   <none>           <none>
    

    安装flannel

    master节点
    kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
    正常会自动pull flannel镜像,如网络不稳定,可以手动pull
    docker pull quay.io/coreos/flannel:v0.11.0-amd64
    node节点在加入k8s之后会自动pull flannel镜像,无需额外配置;
    

    11.node节点加入k8s

     kubeadm join 10.20.0.191:6443 --token qpibgq.aj47u2bq7l7w898x --discovery-token-ca-cert-hash sha256:868e795381864a9234e2a29f96cd6095831e8775a80a1f2c81319569cb876ff4  --ignore-preflight-errors=Swap
    

    查看状态

    [root@k8s-master yum.repos.d]# kubectl get nodes
    NAME         STATUS   ROLES    AGE    VERSION
    k8s-master   Ready    master   144m   v1.13.3
    k8s-node1    Ready    <none>   79m    v1.13.3
    k8s-node2    Ready    <none>   66m    v1.13.3
    

    相关文章

      网友评论

          本文标题:kubeadm安装

          本文链接:https://www.haomeiwen.com/subject/ziipmqtx.html