美文网首页程序员
kubernetes 1.5.1 安装 ( kubeadm ce

kubernetes 1.5.1 安装 ( kubeadm ce

作者: 老吕子 | 来源:发表于2017-03-10 17:11 被阅读1885次

    目录

    1.安装准备
    2.安装过程
    3.参考文档

    一、安装准备

    docker加速器

    由于国内网络问题,强烈建议使用docker hub加速器,
    阿里云请参考:https://yq.aliyun.com/articles/29941
    daocloud请参考:https://www.daocloud.io/mirror#accelerator-doc
    我在此记录为
    https://abc.mirror.aliyuncs.com

    操作系统

    centos 7.2.1511上yum源配置(base epel)
    新增k8s源

    cat /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
    
    

    ntp同步配置(chrony.conf)
    可选:dns配置,如忽略采用/etc/hosts方式

    二、安装过程

    主机名相关

    主机名 ip 角色
    kcluster1 10.9.5.91 master
    kcluster2 10.9.5.90 node
    kcluster3 10.9.5.19 node

    如没有用dns,需更新所有服务器的/etc/hosts

    安装docker(所有服务器)

    sudo yum install docker -y

    ============================================================================================================================================================================================================================================
     Package                                                              Arch                                          Version                                                            Repository                                      Size
    ============================================================================================================================================================================================================================================
    Installing:
     docker                                                               x86_64                                        2:1.10.3-59.el7.centos                                             extras                                          12 M
    

    修改docker启动文件,增加加速器地址
    sudo vim /usr/lib/systemd/system/docker.service

    ExecStart=/usr/bin/docker-current daemon --registry-mirror=https://abc.mirror.aliyuncs.com \
              --exec-opt native.cgroupdriver=systemd \
              $OPTIONS \
              $DOCKER_STORAGE_OPTIONS \
              $DOCKER_NETWORK_OPTIONS \
              $ADD_REGISTRY \
              $BLOCK_REGISTRY \
              $INSECURE_REGISTRY
    

    启动docker
    sudo systemctl daemon-reload && sudo systemctl start docker
    sudo systemctl enable docker.service

    安装k8s软件

    sudo yum install socat kubelet kubeadm kubectl kubernetes-cni -y
    sudo systemctl enable kubelet.service && sudo systemctl start kubelet.service

    配置master(root用户下)

    设置环境变量
    export KUBE_REPO_PREFIX=registry.cn-hangzhou.aliyuncs.com/google-containers
    KUBE_HYPERKUBE_IMAGE=registry.cn-hangzhou.aliyuncs.com/google-containers/hyperkube-amd64:v1.5.1
    KUBE_DISCOVERY_IMAGE=registry.cn-hangzhou.aliyuncs.com/google-containers/kube-discovery-amd64:1.0
    KUBE_ETCD_IMAGE=registry.cn-hangzhou.aliyuncs.com/google-containers/etcd-amd64:3.0.4
    执行配置
    kubeadm init --pod-network-cidr="192.168.0.0/16"

    执行需要一段时间
    最后出现类似如下

    Your Kubernetes master has initialized successfully!
    
    You should now deploy a pod network to the cluster.
    Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:
        http://kubernetes.io/docs/admin/addons/
    
    You can now join any number of machines by running the following on each node:
    
    kubeadm join --token=xxxxxxxxxxxxxxx 10.9.5.91
    

    配置node(root用户下)

    kubeadm join --token=xxxxxxxxxxxxxx 10.9.5.91
    下面是执行命令前后的变化

    [root@cloud4ourself-kcluster1 ~]# kubectl get nodes
    NAME                                STATUS         AGE
    cloud4ourself-kcluster1.novalocal   Ready,master   16m
    [root@cloud4ourself-kcluster1 ~]# kubectl get nodes
    NAME                                STATUS         AGE
    cloud4ourself-kcluster1.novalocal   Ready,master   16m
    cloud4ourself-kcluster2.novalocal   Ready          3s
    

    配置网络(master节点root用户下)

    wget https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml

    修改网段(也可不修改)和image

    由
    "Network": "10.244.0.0/16",
    改为
    "Network": "192.168.0.0/16",
    
    两个image
    由
    image: quay.io/coreos/flannel:v0.7.0-amd64
    改为
    image: docker.io/4admin2root/flannel:v0.7.0-amd64
    
    

    执行kubectl apply -f kube-flannel.yml
    此处也可以改为其他网络模式,请参考https://kubernetes.io/docs/admin/addons/

    检查pod状态
    kubectl --namespace=kube-system get po -o wide
    直到所有都为 Running

    配置dashboard(master节点root用户下)

    kubectl apply -f http://k8s.oss-cn-shanghai.aliyuncs.com/kube/kubernetes-dashboard1.5.0.yaml

    kubectl get svc --namespace=kube-system
    取得访问地址
    http://kcluster1:31810/#/workload?namespace=_all

    验证

    [root@cloud4ourself-kcluster1 ~]# kubectl create -f https://raw.githubusercontent.com/4admin2root/daocloud/master/my-calc.yaml
    replicationcontroller "my-calc-rc" created
    service "my-calc-service" created
    [root@cloud4ourself-kcluster1 ~]# kubectl create -f https://raw.githubusercontent.com/4admin2root/daocloud/master/my-frontend.yaml
    replicationcontroller "my-frontend-rc" created
    service "my-frontend-service" created
    [root@cloud4ourself-kcluster1 ~]# kubectl get pod
    NAME                    READY     STATUS              RESTARTS   AGE
    kube-flannel-ds-7f69s   2/2       Running             6          40m
    kube-flannel-ds-c7d00   2/2       Running             6          40m
    kube-flannel-ds-p3lww   2/2       Running             0          40m
    my-calc-rc-6fzh6        0/1       ContainerCreating   0          1m
    my-calc-rc-pvhx0        0/1       ContainerCreating   0          1m
    my-frontend-rc-jbt2p    0/1       ContainerCreating   0          58s
    my-frontend-rc-m2svn    0/1       ContainerCreating   0          58s
    [root@cloud4ourself-kcluster1 ~]# kubectl get pod
    NAME                    READY     STATUS    RESTARTS   AGE
    kube-flannel-ds-7f69s   2/2       Running   6          44m
    kube-flannel-ds-c7d00   2/2       Running   6          44m
    kube-flannel-ds-p3lww   2/2       Running   0          44m
    my-calc-rc-6fzh6        1/1       Running   0          4m
    my-calc-rc-pvhx0        1/1       Running   0          4m
    my-frontend-rc-jbt2p    1/1       Running   0          4m
    my-frontend-rc-m2svn    1/1       Running   0          4m
    [root@cloud4ourself-kcluster1 ~]# kubectl get pod -o wide
    NAME                    READY     STATUS    RESTARTS   AGE       IP            NODE
    kube-flannel-ds-7f69s   2/2       Running   6          45m       10.9.5.90     cloud4ourself-kcluster2.novalocal
    kube-flannel-ds-c7d00   2/2       Running   6          45m       10.9.5.19     cloud4ourself-kcluster3.novalocal
    kube-flannel-ds-p3lww   2/2       Running   0          45m       10.9.5.91     cloud4ourself-kcluster1.novalocal
    my-calc-rc-6fzh6        1/1       Running   0          6m        192.168.2.2   cloud4ourself-kcluster3.novalocal
    my-calc-rc-pvhx0        1/1       Running   0          6m        192.168.1.3   cloud4ourself-kcluster2.novalocal
    my-frontend-rc-jbt2p    1/1       Running   0          5m        192.168.1.4   cloud4ourself-kcluster2.novalocal
    my-frontend-rc-m2svn    1/1       Running   0          5m        192.168.2.3   cloud4ourself-kcluster3.novalocal
    [root@cloud4ourself-kcluster1 ~]# kubectl describe svc my-frontend-service
    Name:           my-frontend-service
    Namespace:      default
    Labels:         <none>
    Selector:       app=my-frontend
    Type:           NodePort
    IP:         10.98.166.14
    Port:           <unset> 5000/TCP
    NodePort:       <unset> 30080/TCP
    Endpoints:      192.168.1.4:5000,192.168.2.3:5000
    Session Affinity:   None
    No events.
    [root@cloud4ourself-kcluster1 ~]# kubectl describe svc my-calc-service
    Name:           my-calc-service
    Namespace:      default
    Labels:         <none>
    Selector:       app=my-calc
    Type:           ClusterIP
    IP:         10.105.114.170
    Port:           <unset> 5000/TCP
    Endpoints:      192.168.1.3:5000,192.168.2.2:5000
    Session Affinity:   None
    No events.
    

    三、参考文档

    https://kubernetes.io/docs/admin/addons/
    https://yq.aliyun.com/articles/66474?commentId=6660

    相关文章

      网友评论

        本文标题:kubernetes 1.5.1 安装 ( kubeadm ce

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