91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

kubernetes集群安裝指南:kube-apiserver組件部署

發布時間:2020-07-10 02:01:14 來源:網絡 閱讀:2524 作者:清白之年 欄目:云計算

在kubernetes組件中,master節點組件主要包括:kube-apiserver,kube-controller-manager,kube-scheduler等三個組件,每個組件功能職責分工不同,這里我們將三個組件部署在同一機器上,分別部署了三臺機器。

1 安裝準備

1.1 環境變量定義
#################### Variable parameter setting ######################
KUBE_NAME=kube-apiserver
K8S_INSTALL_PATH=/data/apps/k8s/kubernetes
K8S_BIN_PATH=${K8S_INSTALL_PATH}/sbin
K8S_LOG_DIR=${K8S_INSTALL_PATH}/logs
K8S_CONF_PATH=/etc/k8s/kubernetes
CA_DIR=/etc/k8s/ssl
SOFTWARE=/root/software
VERSION=v1.14.2
PACKAGE="kubernetes-server-${VERSION}-linux-amd64.tar.gz"
DOWNLOAD_URL=“”https://github.com/devops-apps/download/raw/master/kubernetes/${PACKAGE}"
ETCD_ENDPOIDS=https://10.10.10.22:2379,https://10.10.10.23:2379,https://10.10.10.24:2379
ETH_INTERFACE=eth2
LISTEN_IP=$(ifconfig | grep -A 1 ${ETH_INTERFACE} |grep inet |awk '{print $2}')
USER=k8s
SERVICE_CIDR=10.254.0.0/22
NODE_PORT_RANG=8400-9400
1.2 下載和分發 kubernetes 二進制文件

登陸devops機器,訪問kubernetes github 官方地址下載穩定的 realease 包至本機;

wget  $DOWNLOAD_URL -P $SOFTWARE

將kubernetes 軟件包分發到各個master節點服務器

sudo ansible master_k8s_vgs -m copy -a "src=${SOFTWARE}/$PACKAGE dest=${SOFTWARE}/" -b

2 安裝kube-apiserver組件服務

2.1 安裝kube-apiserver二進制文件
### 1.Check if the install directory exists.
if [ ! -d "$K8S_BIN_PATH" ]; then
     mkdir -p $K8S_BIN_PATH
fi

if [ ! -d "$K8S_LOG_DIR/$KUBE_NAME" ]; then
     mkdir -p $K8S_LOG_DIR/$KUBE_NAME
fi

if [ ! -d "$K8S_CONF_PATH" ]; then
     mkdir -p $K8S_CONF_PATH
fi

### 2.Install kube-apiserver binary of kubernetes.
if [ ! -f "$SOFTWARE/kubernetes-server-${VERSION}-linux-amd64.tar.gz" ]; then
     wget $DOWNLOAD_URL -P $SOFTWARE >>/tmp/install.log  2>&1
fi
cd $SOFTWARE && tar -xzf kubernetes-server-${VERSION}-linux-amd64.tar.gz -C ./
cp -fp kubernetes/server/bin/$KUBE_NAME $K8S_BIN_PATH
ln -sf  $K8S_BIN_PATH/$KUBE_NAM /usr/local/bin
chown -R $USER:$USER $K8S_INSTALL_PATH
chmod -R 755 $K8S_INSTALL_PATH
2.3 分發 kubeconfig 文件和證書
分發證書
cd ${CA_DIR}
sudo ansible master_k8s_vgs -m  copy -a "src=ca.pem dest=${CA_DIR}/" -b
sudo ansible master_k8s_vgs -m  copy -a "src=ca-key.pem dest=${CA_DIR}/" -b
sudo ansible master_k8s_vgs -m  copy -a "src=kubernetes.pem dest=${CA_DIR}/" -b
sudo ansible master_k8s_vgs -m  copy -a  "src=kubernetes-key.pem dest=${CA_DIR}/" -b
sudo ansible master_k8s_vgs -m  copy -a  "src=proxy-clinet.pem dest=${CA_DIR}/" -b、
sudo ansible master_k8s_vgs -m  copy -a  "src=proxy-client-key.pem dest=${CA_DIR}/" -b
  • 因為master節點相關組件都部署在同一臺節點上,所有這里把ca根證書公鑰和私鑰都同步到每個master節點主機上;
  • proxy-client主要用于apiserver收集metric server資源使用;
2.4 創建審計策略文件
cat>${K8S_CONF_PATH}/audit-policy.yaml<<EOF
apiVersion: audit.k8s.io/v1beta1
kind: Policy
rules:
  # The following requests were manually identified as high-volume and low-risk, so drop them.
  - level: None
    resources:
      - group: ""
        resources:
          - endpoints
          - services
          - services/status
    users:
      - 'system:kube-proxy'
    verbs:
      - watch
  - level: None
    resources:
      - group: ""
        resources:
          - nodes
          - nodes/status
    userGroups:
      - 'system:nodes'
    verbs:
      - get
  - level: None
    namespaces:
      - kube-system
    resources:
      - group: ""
        resources:
          - endpoints
    users:
      - 'system:kube-controller-manager'
      - 'system:kube-scheduler'
      - 'system:serviceaccount:kube-system:endpoint-controller'
    verbs:
      - get
      - update
  - level: None
    resources:
      - group: ""
        resources:
          - namespaces
          - namespaces/status
          - namespaces/finalize
    users:
      - 'system:apiserver'
    verbs:
      - get
  # Don't log HPA fetching metrics.
  - level: None
    resources:
      - group: metrics.k8s.io
    users:
      - 'system:kube-controller-manager'
    verbs:
      - get
      - list
  # Don't log these read-only URLs.
  - level: None
    nonResourceURLs:
      - '/healthz*'
      - /version
      - '/swagger*'
  # Don't log events requests.
  - level: None
    resources:
      - group: ""
        resources:
          - events
  # node and pod status calls from nodes are high-volume and can be large
  - level: Request
    omitStages:
      - RequestReceived
    resources:
      - group: ""
        resources:
          - nodes/status
          - pods/status
    users:
      - kubelet
      - 'system:node-problem-detector'
      - 'system:serviceaccount:kube-system:node-problem-detector'
    verbs:
      - update
      - patch
  - level: Request
    omitStages:
      - RequestReceived
    resources:
      - group: ""
        resources:
          - nodes/status
          - pods/status
    userGroups:
      - 'system:nodes'
    verbs:
      - update
      - patch
  # deletecollection calls can be large, don't log responses for expected namespace deletions
  - level: Request
    omitStages:
      - RequestReceived
    users:
      - 'system:serviceaccount:kube-system:namespace-controller'
    verbs:
      - deletecollection
  # Secrets, ConfigMaps, and TokenReviews can contain sensitive & binary data,
  # so only log at the Metadata level.
  - level: Metadata
    omitStages:
      - RequestReceived
    resources:
      - group: ""
        resources:
          - secrets
          - configmaps
      - group: authentication.k8s.io
        resources:
          - tokenreviews
  # Get repsonses can be large; skip them.
  - level: Request
    omitStages:
      - RequestReceived
    resources:
      - group: ""
      - group: admissionregistration.k8s.io
      - group: apiextensions.k8s.io
      - group: apiregistration.k8s.io
      - group: apps
      - group: authentication.k8s.io
      - group: authorization.k8s.io
      - group: autoscaling
      - group: batch
      - group: certificates.k8s.io
      - group: extensions
      - group: metrics.k8s.io
      - group: networking.k8s.io
      - group: policy
      - group: rbac.authorization.k8s.io
      - group: scheduling.k8s.io
      - group: settings.k8s.io
      - group: storage.k8s.io
    verbs:
      - get
      - list
      - watch
  # Default level for known APIs
  - level: RequestResponse
    omitStages:
      - RequestReceived
    resources:
      - group: ""
      - group: admissionregistration.k8s.io
      - group: apiextensions.k8s.io
      - group: apiregistration.k8s.io
      - group: apps
      - group: authentication.k8s.io
      - group: authorization.k8s.io
      - group: autoscaling
      - group: batch
      - group: certificates.k8s.io
      - group: extensions
      - group: metrics.k8s.io
      - group: networking.k8s.io
      - group: policy
      - group: rbac.authorization.k8s.io
      - group: scheduling.k8s.io
      - group: settings.k8s.io
      - group: storage.k8s.io
  # Default level for all other requests.
  - level: Metadata
    omitStages:
      - RequestReceived
EOF
2.5 創建kube-apiserver 啟動服務
at >/usr/lib/systemd/system/${KUBE_NAME}.service<<EOF
[Unit]
Description=Kubernetes API Server
Documentation=https://github.com/GoogleCloudPlatform/kubernetes
After=network.target
[Service]
User=${USER}
Type=notify
WorkingDirectory=${K8S_INSTALL_PATH}
EnvironmentFile=-${K8S_CONF_PATH}/${KUBE_NAME}
ExecStart=${K8S_BIN_PATH}/${KUBE_NAME} \\
  --enable-admission-plugins=NodeRestriction \\
  --bind-address=0.0.0.0 \\
  --insecure-bind-address=${LISTEN_IP} \\
  --insecure-port=8080 \\
  --secure-port=6443 \\
  --advertise-address=${LISTEN_IP} \\
  --authorization-mode=Node,RBAC \\
  --anonymous-auth=false \\
  --runtime-config=api/all \\
  --enable-bootstrap-token-auth=true \\
  --token-auth-file=${K8S_CONF_PATH}/token.csv \\
  --service-cluster-ip-range=${SERVICE_CIDR} \\
  --service-node-port-range=${NODE_PORT_RANG} \\
  --requestheader-allowed-names="" \\
  --requestheader-client-ca-file=${CA_DIR}/ca.pem \\
  --requestheader-extra-headers-prefix="X-Remote-Extra-" \\
  --requestheader-group-headers=X-Remote-Group \\
  --requestheader-username-headers=X-Remote-User \\
  --tls-cert-file=${CA_DIR}/kubernetes.pem \\
  --tls-private-key-file=${CA_DIR}/kubernetes-key.pem \\
  --client-ca-file=${CA_DIR}/ca.pem \\
  --service-account-key-file=${CA_DIR}/ca.pem \\
  --etcd-cafile=${CA_DIR}/ca.pem \\
  --etcd-certfile=${CA_DIR}/etcd.pem \\
  --etcd-keyfile=${CA_DIR}/etcd-key.pem \\
  --etcd-servers=${ETCD_ENDPOIDS} \\
  --delete-collection-workers=2 \\
  --default-watch-cache-size=200 \\
  --kubelet-certificate-authority=${CA_DIR}/ca.pem \\
  --kubelet-client-certificate=${CA_DIR}/kubernetes.pem \\
  --kubelet-client-key=${CA_DIR}/kubernetes-key.pem \\
  --kubelet-https=true \\
  --kubelet-timeout=10s \\
  --proxy-client-cert-file=${CA_DIR}/proxy-client.pem \\
  --proxy-client-key-file=${CA_DIR}/proxy-client-key.pem \\
  --enable-aggregator-routing=true \\
  --enable-swagger-ui=true \\
  --allow-privileged=true \\
  --apiserver-count=3 \\
  --audit-log-mode=batch \\
  --audit-log-truncate-enabled=true \\
  --audit-log-batch-buffer-size=20000 \\
  --audit-log-batch-max-size=3 \\
  --audit-log-maxage=15 \\
  --audit-log-maxbackup=3 \\
  --audit-log-maxsize=100 \\
  --audit-log-path=${K8S_LOG_DIR}/${KUBE_NAME}/audit.log \\
  --audit-policy-file=${K8S_CONF_PATH}/audit-policy.yaml \\
  --storage-backend=etcd3 \\
  --max-mutating-requests-inflight=2000 \\
  --max-requests-inflight=4000 \\
  --event-ttl=168h \\
  --alsologtostderr=true \\
  --logtostderr=false \\
  --log-dir=${K8S_LOG_DIR}/${KUBE_NAME} \\
  --v=2
Restart=on-failure
RestartSec=5
LimitNOFILE=65536
[Install]
WantedBy=multi-user.target
EOF
  • --advertise-address:apiserver 對外通告的 IP(kubernetes 服務后端節點 IP);
  • --default-*-toleration-seconds:設置節點異常相關的閾值;
  • --max-*-requests-inflight:請求相關的最大閾值;
  • --etcd-*:訪問 etcd 的證書和 etcd 服務器地址;
  • --experimental-encryption-provider-config:指定用于加密 etcd 中 secret 的配置;
  • --bind-address: https 監聽的 IP,不能為 127.0.0.1,否則外界不能訪問它的安全端口 6443;
  • --secret-port:https 監聽端口;
  • --insecure-port=0:關閉監聽 http 非安全端口(8080);
  • --tls-*-file:指定 apiserver 使用的證書、私鑰和 CA 文件;
  • --audit-*:配置審計策略和審計日志文件相關的參數;
  • --client-ca-file:驗證 client (kue-controller-manager、kube-scheduler、kubelet、kube-proxy 等)請求所帶的證書;
  • --enable-bootstrap-token-auth:啟用 kubelet bootstrap 的 token 認證;
  • --requestheader-*:kube-apiserver 的 aggregator layer 相關的配置參數,proxy-client & HPA 需要使用;
  • --requestheader-client-ca-file:用于簽名 --proxy-client-cert-file 和 --proxy-client-key-file 指定的證書;在啟用了 metric aggregator 時使用;
  • --requestheader-allowed-names:不能為空,值為逗號分割的 --proxy-client-cert-file 證書的 CN 名稱,這里設置為 "aggregator";
  • --service-account-key-file:簽名 ServiceAccount Token 的公鑰文件,kube-controller-manager 的 --service-account-private-key-file 指定私鑰文件,兩者配對使用;
  • --runtime-config=api/all=true: 啟用所有版本的 APIs,如 autoscaling/v2alpha1;
  • --authorization-mode=Node,RBAC、--anonymous-auth=false: 開啟 Node 和 RBAC 授權模式,拒絕未授權的請求;
  • --enable-admission-plugins:啟用一些默認關閉的 plugins;
  • --allow-privileged:運行執行 privileged 權限的容器;
  • --apiserver-count=3:指定 apiserver 實例的數量;
  • --event-ttl:指定 events 的保存時間;
  • --kubelet-:如果指定,則使用 https 訪問 kubelet APIs;需要為證書對應的用戶(上面 kubernetes.pem 證書的用戶為 kubernetes) 用戶定義 RBAC 規則,否則訪問 kubelet API 時提示未授權;
  • --proxy-client-*:apiserver 訪問 metrics-server 使用的證書;
  • --service-cluster-ip-range: 指定 Service Cluster IP 地址段;
  • --service-node-port-range: 指定 NodePort 的端口范圍;
  • kube-apiserver 的 --requestheader-allowed-names 參數需要與metric證書CN字段一致,否則后續訪問 metrics 時會提示權限不足。
  • 如果 kube-apiserver 機器沒有運行 kube-proxy,則還需要添加 --enable-aggregator-routing=true 參數;
  • 關于 --requestheader-XXX 相關參數,參考:

    https://github.com/kubernetes-incubator/apiserver-builder/blob/master/docs/concepts
    https://docs.bitnami.com/kubernetes/how-to/configure-autoscaling-custom-metrics/

    注意:

    1. requestheader-client-ca-file 指定的 CA 證書,必須具有 client auth and server auth;
    2. 如果 --requestheader-allowed-names 為空,或者 --proxy-client-cert-file 證書的 CN 名稱不在 allowed-names 中,則后續查看 node 或 pods 的 metrics 失敗,提示:
  • requestheader-client-ca-file 指定的 CA 證書,必須具有 client auth and server auth;
  • 如果 --requestheader-allowed-names 為空,或者 --proxy-client-cert-file 證書的 CN 名稱不在 allowed-names 中,則后續查看 node 或 pods 的 metrics 失敗,提示:
    ###### Error from server (Forbidden): nodes.metrics.k8s.io is forbidden..
2.6 檢查kube-apiserver服務及監聽的端口
sudo systemctl status kube-apiserver |grep 'Active:'

確保狀態為 active (running),否則查看日志,確認原因:

sudo journalctl -u kube-apiserver
2.7 打印 kube-apiserver 寫入 etcd 的數據(可選)
ETCDCTL_API=3 etcdctl \
    --endpoints=${ETCD_ENDPOINTS} \
    --cacert=/etc/k8s/ssl/ca.pem \
    --cert=/etc/k8s/ssl/etcd.pem \
    --key=/etc/k8s/ssl/etcd-key.pem \
    get /registry/ --prefix --keys-only
2.8 檢查集群信息
kubectl cluster-info
2.9 授予 kube-apiserver 訪問 kubelet API 的權限

在執行 kubectl exec、run、logs 等命令時,apiserver 會將請求轉發到 kubelet 的 https 端口。這里定義 RBAC 規則,授權 apiserver 使用的證書(kubernetes.pem)用戶名(CN:kuberntes)訪問 kubelet API 的權限:

kubectl create \
  clusterrolebinding kube-apiserver:kubelet-apis \
  --clusterrole=system:kubelet-api-admin \
  --user kubernetes

kube-apiserver安裝完成,繼續安裝其他master組件:kube-controller-manager,具體安裝文檔請參考:kubernetes集群安裝指南:kube-controller-manager組件集群部署,關于kube-apiserver腳本請從此處獲取;

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

德惠市| 波密县| 丹寨县| 慈溪市| 秭归县| 随州市| 巩义市| 南昌市| 西贡区| 岚皋县| 吴忠市| 宁国市| 平谷区| 荔波县| 肇州县| 柳州市| 河东区| 广德县| 新干县| 蒙城县| 肇源县| 镇赉县| 栾城县| 朝阳县| 章丘市| 百色市| 通山县| 渝北区| 禹城市| 胶南市| 晋城| 呼和浩特市| 邢台市| 广平县| 屏东市| 玉屏| 县级市| 邹平县| 商南县| 肇东市| 凤山县|