ETCDクラスターの1つの展開
1.1ETCDをインストールする
etcdは、CoreOSによって開発されたRaftに基づく分散型Key-Valueストレージシステムであり、サービスディスカバリ、共有構成、および同時実行制御(リーダー選出、分散ロックなど)によく使用されます。kubernetesはetcdを使用してすべてのオペレーティングデータを保存します。
1 etcdは、CoreOSによって開発されたRaftに基づく分散型Key-Valueストレージシステムであり、サービスディスカバリ、共有構成、および同時実行制御(リーダー選出、分散ロックなど)によく使用されます。kubernetesはetcdを使用してすべてのオペレーティングデータを保存します。 2 [ルート@ k8smaster01〜]#のCDは/ opt / K8S /作業 3 [k8smaster01仕事@ルート]#wgetのHTTPS://github.com/coreos/etcd/releases/download/v3.3.13/etcd-v3.3.13- linux-amd64.tar.gz 4 [root @ k8smaster01 work] #tar -xvf etcd-v3.3.13-linux-amd64.tar.gz
1.2ETCDを配布する
1 [ルート@ k8smaster01〜]#のCDは/ opt / K8S /仕事 2 [ルート@ k8smaster01仕事]#ソース/opt/k8s/bin/environment.sh 3 [k8smaster01仕事@ルート]#用MASTER_IPで$ {MASTER_IPS [@ ]} 4 do 5 echo " >>> $ {master_ip} " 6 scp etcd-v3.3.13-linux-amd64 / etcd * root @ $ {master_ip}:/ opt / k8s / bin 7 ssh root @ $ {master_ip} " chmod + x / opt / k8s / bin / * " 8 完了
1.3etcd証明書とキーを作成する
1 [root @ k8smaster01〜] #cd / opt / k8s / work 2 [root @ k8smaster01 work] #cat> etcd-csr.json << EOF 3 { 4 " CN ": " etcd "、 5 " hosts ":[ 6 " 127.0.0.1 "、 7 " 172.24.8.71 "、 8 " 172.24.8.72 "、 9 " 172.24.8.73 " 10 ]、 11 "キー":{ 12 "algo ":" rsa "、 13 "サイズ":2048 14 }、 15 "名前":[ 16 { 17 " C ": " CN "、 18 " ST ": "上海"、 19 " L ": "上海"、 20 " O ": " k8s "、 21 " OU ":"システム" 22 } 23 ] 24} 25 EOF 26 #etcdCA証明書要求ファイルの作成
説明:
ホストフィールドは、証明書の使用を許可されたetcdノードのIPまたはドメイン名リストを指定し、etcdクラスターの3つのノードIPをリストする必要があります。
1 [root @ k8smaster01〜] #cd / opt / k8s / work 2 [root @ k8smaster01 work] #cfssl gencert -ca = / opt / k8s / work / ca.pem \ 3 -ca-key = / opt / k8s / work / ca-key.pem -config = / opt / k8s / work / ca-config.json \ 4 -profile = kubernetes etcd-csr.json | cfssljson -bare etcd#生成CA密钥(ca-key.pem)和证书(ca.pem)
1.4証明書と秘密鍵を配布する
1 [ルート@ k8smaster01〜]#のCDは/ opt / K8S /仕事 2 [ルート@ k8smaster01仕事]#ソース/opt/k8s/bin/environment.sh 3 [k8smaster01仕事@ルート]#用MASTER_IPで$ {MASTER_IPS [@ ]} 4 do 5 echo " >>> $ {master_ip} " 6 ssh root @ $ {master_ip} " mkdir -p / etc / etcd / cert " 7 scp etcd * .pem root @ $ {master_ip}:/ etc / etcd / cert / 8 完了
1.5 etcdsystemdを作成する
1 [root @ k8smaster01〜] #cd / opt / k8s / work 2 [root @ k8smaster01 work] #source /opt/k8s/bin/environment.sh 3 [root @ k8smaster01 work] #cat> etcd.service.template < <EOF 4 [Unit] 5 Description = Etcd Server 6 After = network.target 7 After = network-online.target 8 Wants = network-online.target 9 Documentation = https://github.com/coreos 10 11 [サービス] 12 Type = notify 13 WorkingDirectory = $ {ETCD_DATA_DIR} 14 ExecStart = / opt / k8s / bin / etcd \\ 15 --data-DIR = $ {ETCD_DATA_DIR} \\ 16 --wal-DIR = $ {ETCD_WAL_DIR} \\ 17 -名= ##をmaster_name ## \\ 18 --certファイル=の/ etc / etcd / CERT /etcd.pem \\ 19 --keyファイル=の/ etc / etcd / CERT / etcd-key.pem \\ 20 --trusted-CA-ファイル=の/ etc / kubernetes / CERT / ca.pem \\ 21 - -peer-cert-file = / etc / etcd / cert / etcd.pem \\ 22 --peer-key-file = / etc / etcd / cert / etcd-key.pem \\ 23 --peer-trusted-ca -file = / etc / kubernetes / cert / ca.pem \\ 24 --peer-client-cert-auth \\ 25 --client-cert-auth \\ 26 --listen-peer-urls = https:// ## MASTER_IP ##:2380 \\ 27 --initial-advertise-peer-urls = https:// ## MASTER_IP ##:2380 \\ 28 --listen-client-urls = https:// ## MASTER_IP ##:2379、http: //127.0.0.1 :2379 \\ 29 --advertise-client-urls = https:// ## MASTER_IP ##:2379 \\ 30 --initial-cluster-token = etcd- cluster-0 \\ 31 --initial-cluster = $ {ETCD_NODES} \\ 32 --initial -cluster-state = new \\ 33 --auto-compaction-mode = periodic \\ 34 --auto-compaction-retention = 1 \\ 35 --max-request-bytes = 33554432 \\ 36 --quota-backend-bytes = 6442450944 \\ 37 --heartbeat-interval = 250 \\ 38 --election-timeout = 2000 39 restart = on-failure 40 restartSec = 5 41 LimitNOFILE = 65536 42 43 [インストール] 44 WantedBy = multi-user.target 45 EOF
説明:
WorkingDirectory、-data-dir:作業ディレクトリとデータディレクトリを$ {ETCD_DATA_DIR}として指定します。これは、サービスを開始する前に作成する必要があります。
--wal-dir:walディレクトリを指定します。パフォーマンスを向上させるために、通常はSSDまたは--data-dirとは異なるディスクを使用します。
--name:ノード名を指定します。--initial-cluster-stateの値が新しい場合、-nameのパラメーター値は--initial-clusterのリストに含まれている必要があります。
--cert-file、-key-file:etcdサーバーがクライアントと通信するときに使用される証明書と秘密鍵。
--trusted-ca-file:クライアント証明書に署名したCA証明書で、クライアント証明書の検証に使用されます。
--peer-cert-file、-peer-key-file:etcdがピアと通信するために使用する証明書と秘密鍵。
--peer-trusted-ca-file:ピア証明書に署名したCA証明書で、ピア証明書の検証に使用されます。
1.6systemdの対応するアドレスを変更する
1 [ルート@ k8smaster01〜]#のCD / OPT / K8S /ワーク 2 [ルート@ k8smaster01作業]#ソース/opt/k8s/bin/environment.sh 3 [k8smaster01作業@ルート]#するための((I = 0;私<3; i ++)) 4 do 5 sed -e " s / ## MASTER_NAME ## / $ {MASTER_NAMES [i]} / " -e " s / ## MASTER_IP ## / $ {MASTER_IPS [i]} / " etcd.service.template> etcd - $ {MASTER_IPS [I]}サービス 6 行います
1.7 etcdsystemdを配布する
1 [ルート@ k8smaster01〜]#のCDは/ opt / K8S /仕事 2 [ルート@ k8smaster01仕事]#ソース/opt/k8s/bin/environment.sh 3 [k8smaster01仕事@ルート]#用MASTER_IPで$ {MASTER_IPS [@ ]} 4 do 5 echo " >>> $ {master_ip} " 6 scp etcd- $ {master_ip} .service root @ $ {master_ip}:/ etc / systemd / system / etcd.service 7 done
2つの開始と検証
2.1ETCDを開始する
1 [ルート@ k8smaster01〜]#のCDは/ opt / K8S /仕事 2 [ルート@ k8smaster01仕事]#ソース/opt/k8s/bin/environment.sh 3 [k8smaster01仕事@ルート]#用MASTER_IPで$ {MASTER_IPS [@ ]} 4 do 5 echo " >>> $ {master_ip} " 6 ssh root @ $ {master_ip} " mkdir -p $ {ETCD_DATA_DIR} $ {ETCD_WAL_DIR} " 7 ssh root @ $ {master_ip} " systemctlデーモン-リロード&& systemctl enable etcd && systemctl restart etcd "& 8 完了
2.2ETCDの起動を確認する
1 [ルート@ k8smaster01〜]#のCDは/ opt / K8S /仕事 2 [ルート@ k8smaster01仕事]#ソース/opt/k8s/bin/environment.sh 3 [k8smaster01仕事@ルート]#用MASTER_IPで$ {MASTER_IPS [@ ]} 4 do 5 echo " >>> $ {master_ip} " 6 ssh root @ $ {master_ip} " systemctl status etcd | grep Active " 7 done
2.3サービスステータスの確認
1 [ルート@ k8smaster01〜]#のCDは/ opt / K8S /仕事 2 [ルート@ k8smaster01仕事]#ソース/opt/k8s/bin/environment.sh 3 [k8smaster01仕事@ルート]#用MASTER_IPで$ {MASTER_IPS [@ ]} 4 do 5 echo " >>> $ {master_ip} " 6 ETCDCTL_API = 3 / opt / k8s / bin / etcdctl \ 7 --endpoints = https:// $ {master_ip}:2379 \ 8 --cacert = / etc / kubernetes / cert / ca.pem \ 9 --cert = / etc / etcd / cert / etcd.pem \ 10 --key = / etc / etcd / cert /etcd-key.pemエンドポイントヘルス 11 完了
2.4ETCDの現在のリーダーを見る
1 [root @ k8smaster01〜] #source /opt/k8s/bin/environment.sh 2 [root @ k8smaster01〜] #ETCDCTL_API = 3 / opt / k8s / bin / etcdctl \ 3 -w table --cacert = / etc / kubernetes / cert / ca.pem \ 4 --cert = / etc / etcd / cert / etcd.pem \ 5 --key = / etc / etcd / cert / etcd-key.pem \ 6 --endpoints = $ {ETCD_ENDPOINTS }エンドポイントステータス
上に示したように、ETCDクラスターの現在のリーダーは172.24.8.71です。