角色 | 系統 | 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 | 1.17.2 |
etcd | v3.3.18 |
coredns | 1.6.6(docker鏡像) |
Flanel | v0.11.0 |
docker | 18.09 |
關閉swapnode
sudo swapoff -a sudo sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab
配置經常使用軟件安裝源
在/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
建立工做目錄github
mkdir -p /opt/k8s/{bin,work} /etc/{kubernetes,etcd}/cert
將 /opt/k8s/bin追加到$PATH中docker
echo 'PATH=/opt/k8s/bin:$PATH' >>/root/.bashrc source /root/.bashrc
安裝ssh服務,並設置root能夠執行json
apt install openssh-server #編輯/etc/ssh/sshd_config文件,在#PermitRootLogin prohibit-password下追加PermitRootLogin yes ,重啓ssh服務 systemctl restart ssh.service
安裝依賴工具包ubuntu
apt install -y ipvsadm ipset curl jq socat
設置主機名api
cat >> /etc/hosts <<EOF 192.168.0.107 master 192.168.0.114 slave EOF
添加節點信任關係,只用在master節點上執行bash
ssh-keygen -t rsa ssh-copy-id root@192.168.0.114
安裝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/*
建立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
建立證書籤名請求文件
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
生成證書
cd /opt/k8s/work cfssl gencert -initca ca-csr.json | cfssljson -bare ca ls ca*
安裝證書
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/