kubernetes(二)二進制安裝-環境準備

系統信息

角色 系統 CPU Core 內存 主機名稱 ip 安裝組件
master 18.04.1-Ubuntu 4 8G master 192.168.0.107 kubectl,kube-apiserver,kube-controller-manager,kube-scheduler,etcd,flannald
slave 18.04.1-Ubuntu 4 4G slave 192.168.0.114 docker,flannald,kubelet,kube-proxy,coredns

k8s&docker版本

軟件 版本
k8s 1.17.2
etcd v3.3.18
coredns 1.6.6(docker鏡像)
Flanel v0.11.0
docker 18.09

安裝前準備(主節點和從節點都須要執行)

  1. 關閉swapnode

    sudo swapoff -a 
    sudo  sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab
  2. 配置經常使用軟件安裝源
    在/etc/apt/sources.list.d/ 追加system.list文件,內容以下linux

    deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted  
    deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted  
    deb http://mirrors.aliyun.com/ubuntu/ bionic universe  
    deb http://mirrors.aliyun.com/ubuntu/ bionic-updates universe  
    deb http://mirrors.aliyun.com/ubuntu/ bionic multiverse  
    deb http://mirrors.aliyun.com/ubuntu/ bionic-updates multiverse  
    deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse

    執行git

    sudo apt-get update
  3. 建立工做目錄github

    mkdir -p /opt/k8s/{bin,work} /etc/{kubernetes,etcd}/cert
  4. 將 /opt/k8s/bin追加到$PATH中docker

    echo 'PATH=/opt/k8s/bin:$PATH' >>/root/.bashrc
    source /root/.bashrc
  5. 安裝ssh服務,並設置root能夠執行json

    apt install openssh-server
    
    #編輯/etc/ssh/sshd_config文件,在#PermitRootLogin prohibit-password下追加PermitRootLogin yes ,重啓ssh服務
    
    systemctl restart ssh.service
  6. 安裝依賴工具包ubuntu

    apt install -y ipvsadm ipset curl jq socat
  7. 設置主機名api

    cat >> /etc/hosts <<EOF
    192.168.0.107 master
    192.168.0.114 slave
    EOF
  8. 添加節點信任關係,只用在master節點上執行bash

    ssh-keygen -t rsa 
    ssh-copy-id root@192.168.0.114

建立CA根證書和祕鑰(在master節點上執行)

  1. 安裝cfssl工具集ssh

    cd /opt/k8s/work
    
    wget https://github.com/cloudflare/cfssl/releases/download/v1.4.1/cfssl_1.4.1_linux_amd64
    cp cfssl_1.4.1_linux_amd64 /opt/k8s/bin/cfssl
    
    wget https://github.com/cloudflare/cfssl/releases/download/v1.4.1/cfssljson_1.4.1_linux_amd64
    cp cfssljson_1.4.1_linux_amd64 /opt/k8s/bin/cfssljson
    
    wget https://github.com/cloudflare/cfssl/releases/download/v1.4.1/cfssl-certinfo_1.4.1_linux_amd64
    cp cfssl-certinfo_1.4.1_linux_amd64 /opt/k8s/bin/cfssl-certinfo
    
    chmod +x /opt/k8s/bin/*
  2. 建立CA配置文件

    cd /opt/k8s/work
    cat > ca-config.json <<EOF
    {
      "signing": {
        "default": {
          "expiry": "87600h"
        },
        "profiles": {
          "kubernetes": {
            "usages": [
                "signing",
                "key encipherment",
                "server auth",
                "client auth"
            ],
            "expiry": "87600h"
          }
        }
      }
    }
    EOF
    • signing:表示該證書可用於簽名其它證書(生成的 ca.pem 證書中 CA=TRUE);
    • server auth:表示 client 能夠用該該證書對 server 提供的證書進行驗證;
    • client auth:表示 server 能夠用該該證書對 client 提供的證書進行驗證;
    • expiry : "87600h":證書有效期設置爲 10 年;
  3. 建立證書籤名請求文件

    cd /opt/k8s/work
    cat > ca-csr.json <<EOF
    {
      "CN": "kubernetes",
      "key": {
        "algo": "rsa",
        "size": 2048
      },
      "names": [
        {
          "C": "CN",
          "ST": "NanJing",
          "L": "NanJing",
          "O": "k8s",
          "OU": "system"
        }
      ],
      "ca": {
        "expiry": "87600h"
     }
    }
    EOF
  4. 生成證書

    cd /opt/k8s/work
    cfssl gencert -initca ca-csr.json | cfssljson -bare ca
    ls ca*
  5. 安裝證書

    cd /opt/k8s/work
    
    cp ca*.pem ca-config.json /etc/kubernetes/cert
    
    # 分發到從節點
    export node_ip=192.168.0.114
    scp ca*.pem ca-config.json root@${node_ip}:/etc/kubernetes/cert/
相關文章
相關標籤/搜索