本指南說明如何在裸機叢集中設定 Kubernetes 適用的 OpenStack Cloud Provider。必須設定 OpenStack Cloud Provider,才能使用 OpenStack LBaaS 公開 Kubernetes 服務。
必要條件
本指南假設您已在 OpenStack 環境中建立叢集,並執行 Google Distributed Cloud,設定方式與「在 OpenStack 上部署裸機叢集」指南中的說明類似。請先按照該指南操作,再嘗試這些步驟。
設定提供者
以下各節假設您是從本機工作站的終端機視窗開始操作。
取得 OpenStack 用戶端設定 (
openrc
) 檔案。您可以從 OpenStack WebUI 下載。source PATH_TO_OPENRC_FILE/openrc
為 OpenStack Kubernetes 雲端服務供應商建立設定檔。
cat > cloud.conf << EOF [Global] auth-url=${OS_AUTH_URL} username=${OS_USERNAME} password=${OS_PASSWORD} region=RegionOne tenant-name=admin domain-id=default # this is for using a self-signed cert if your using a CA then comment this line # and point to the CA certificate using the "ca-file" arg tls-Insecure=true [LoadBalancer] use-octavia=true # this is generally the public network on OpenStack floating-network-id=PUBLIC_NETWORK_ID # this should be private network subnet where vip is allocated for the ABM nodes subnet-id=ABM_NETWORK_SUBNET_ID [BlockStorage] bs-version=v2 EOF
更改下列內容:
OS_AUTH_URL
、OS_USERNAME
、OS_PASSWORD
:這些變數應已透過來源openrc
檔案在環境中設定。因此系統會自動選取這些檔案。PUBLIC_NETWORK_ID
:這是 OpenStack 部署作業中可公開存取的網路,浮動 IP 位址會從這個網路分配。系統會從這個網路指派 Kubernetes 服務的LoadBalancer IPs
。您可以使用單行指令,從 OpenStack 環境擷取這個 IP。ABM_NETWORK_SUBNET_ID
:這是 OpenStack 部署作業中私人網路的子網路,Google Distributed Cloud 軟體專用 VM 的 IP 會從這個子網路分配。您可以使用類似「在 OpenStack 中取得公用網路的 ID」的指令,從 OpenStack 環境擷取這個 IP。
擷取
abm-ws
VM 的公開浮動 IP 位址。export OPENSTACK_IPS=$(openstack floating ip list --tags=abm_ws_floatingip -f json) export FLOATING_IP=$(jq -c '.[]."Floating IP Address"' <<< $OPENSTACK_IPS | tr -d '"')
將
cloud.conf
檔案複製到 OpenStack 中的abm-ws
VM。scp ./cloud.conf ubuntu@$FLOATING_IP:~
使用 SSH 安全連線至
abm-ws
VM,並以root
使用者身分登入。Terraform 指令碼設定的
root
使用者為abm
。ssh ubuntu@$FLOATING_IP sudo -u abm -i
將
cloud.conf
檔案複製到root
使用者的$HOME
目錄。cp /home/ubuntu/cloud.conf $HOME
使用設定建立
Kubernetes Secret
。# make sure the kubectl client is pointing towards your cluster export KUBECONFIG=~/bmctl-workspace/CLUSTER_NAME/CLUSTER_NAME-kubeconfig # store the provider configurations as a Kubernetes secret kubectl create secret -n kube-system generic cloud-config --from-file=cloud.conf
安裝 Kubernetes 適用的 OpenStack 雲端服務供應商。
# create the necessary roles for the OpenStack provider kubectl apply -f https://raw.githubusercontent.com/kubernetes/cloud-provider-openstack/master/manifests/controller-manager/cloud-controller-manager-roles.yaml # create the required role-bindings for the OpenStack provider kubectl apply -f https://raw.githubusercontent.com/kubernetes/cloud-provider-openstack/master/manifests/controller-manager/cloud-controller-manager-role-bindings.yaml # create the OpenStack controller manager kubectl apply -f https://raw.githubusercontent.com/kubernetes/cloud-provider-openstack/master/manifests/controller-manager/openstack-cloud-controller-manager-ds.yaml
驗證 OpenStack 整合
部署範例銷售點應用程式。
kubectl apply -f https://raw.githubusercontent.com/GoogleCloudPlatform/anthos-samples/master/anthos-bm-openstack-terraform/resources/point-of-sales.yaml
確認應用程式 Pod 是否正在執行。
kubectl get pods
預期輸出內容:
NAME READY STATUS RESTARTS AGE api-server-7db4777f7f-zflk5 1/1 Running 0 74s inventory-58c6fb5568-dqk2x 1/1 Running 0 74s payments-68d5d65d5c-5mjl6 1/1 Running 0 74s
透過
LoadBalancer
類型的服務公開應用程式。kubectl apply -f https://raw.githubusercontent.com/GoogleCloudPlatform/anthos-samples/master/anthos-bm-openstack-terraform/resources/point-of-sales-service.yaml
請嘗試透過瀏覽器存取服務。
# wait for the external IP to be assigned kubectl get service api-server-lb NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE api-server-lb LoadBalancer 10.203.77.215 172.29.249.159 80:32378/TCP 4m12s
使用
EXTERNAL-IP
存取銷售點應用程式。前往 OpenStack WebUI,即可看到 OpenStack 正在建立新的 OpenStack Load Balancer。