使用kubeadm安裝Kubernetes

  1. Docker安裝
    yum install -y yum-utils
    yum-config-manager --add-repo https://docs.docker.com/v1.13/engine/installation/linux/repo_files/centos/docker.repo
    yum makecache fast
    yum list docker-engine.x86_64 --showduplicates |sort -r
    rpm -qa | grep docker*
    yum install -y docker-engine-1.12.6
    systemctl start docker
    systemctl enable docker

    Kubernetes 1.6尚未針對docker 1.13和最新的docker 17.03上作測試和驗證,因此這裏安裝Kubernetes官方推薦的Docker 1.12版本node

  2. 添加kubernetes源
    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
    EOF
    
    cat >> /etc/sysctl.d/k8s.conf <<EOF
    net.bridge.bridge-nf-call-ip6tables = 1  net.bridge.bridge-nf-call-iptables = 1
    EOF
    
    sysctl -p /etc/sysctl.d/k8s.conf
  3. 安裝k8s服務
    yum install -y kubelet kubeadm kubectl kubernetes-cni
    systemctl enable kubelet.service
    systemctl restart kubelet.service
  4. 全部節點添加hosts
    cat >> /etc/hosts <<EOF
    10.10.24.237 k8s-master
    10.10.24.236 k8s-node-1
    10.10.24.232 k8s-node-2
    EOF
  5. 主節點初始化集羣
    kubeadm init --kubernetes-version=v1.7.5 --pod-network-cidr=10.244.0.0/16 --apiserver-advertise-address=10.10.24.237
    網絡問題沒法從google下載容器鏡像:
    [apiclient] Created API client, waiting for the control plane to become ready
    卡住須要執行kubeadm reset清理,從新執行
    init成功後k8s的核心組件均正常啓動,以container的形式啓動:ps -ef|grep kube
    爲了使用kubectl訪問apiserver,在~/.bash_profile中追加下面的環境變量:
    export KUBECONFIG=/etc/kubernetes/admin.conf
    source ~/.bash_profile
    此時kubectl命令在master node上就能夠用了,查看一下當前機器中的Node:
    kubectl get nodes
  6. 向集羣中添加節點
    將node1和node2加入集羣,分別在node1和node2上執行:
    kubeadm join --token e7986d.e440de5882342711 10.10.24.237:6443
    使master node參與工做負載
    kubectl taint nodes --all node-role.kubernetes.io/master-
    使用kubeadm初始化的集羣,出於安全考慮Pod不會被調度到Master Node上,也就是說Master Node不參與工做負載
  7. 全部節點安裝flannel pod網絡
    kubectl create -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel-rbac.yml
    kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
    serviceaccount "flannel" created
    configmap "kube-flannel-cfg" created
    daemonset "kube-flannel-ds" created
    ps -ef|grep kube|grep flannel
    使用kubectl get pod --all-namespaces -o wide確保全部的Pod都處於Running
  8. 安裝Dashboard插件
    wget https://raw.githubusercontent.com/kubernetes/dashboard/master/src/deploy/kubernetes-dashboard.yaml
    kubectl create -f kubernetes-dashboard.yaml
    kubectl create -f kube-dashboard-rbac.yml
    kind: ClusterRoleBinding
    apiVersion: rbac.authorization.k8s.io/v1beta1
    metadata:
    name: dashboard-admin
    roleRef:
    apiGroup: rbac.authorization.k8s.io
    kind: ClusterRole
    name: cluster-admin
    subjects:
    - kind: ServiceAccount
    name: default
    namespace: kube-system
    kube-dashboard-rbac.yml

    kubectl create -f dashboard-rbac.ymllinux

  9. 在集羣中運行Heapster wget https://github.com/kubernetes/heapster/archive/v1.3.0.tar.gztar -zxvf v1.3.0.tar.gzcd heapster-1.3.0/deploy/kube-config/influxdbkubectl create -f ./deployment "monitoring-grafana" createdservice "monitoring-grafana" createddeployment "heapster" createdservice "heapster" createddeployment "monitoring-influxdb" createdservice "monitoring-influxdb" created
相關文章
相關標籤/搜索