為 OpenShift 4 準備 NCP
Last Updated January 23, 2025

安裝 OpenShift 4 之前,您必須更新某些 NCP 組態檔。
先執行下列命令,以取得 NSX Container Plugin 操作員 YAML 規格:
git clone https://github.com/vmware/nsx-container-plugin-operator.git
下列檔案位於
nsx-container-plugin-operator/deploy
資料夾中:
  • configmap.yaml
    - 使用 NSX-T 資訊更新此檔案。
  • operator.yaml
    - 在此檔案中指定 NCP 映像位置。
  • namespace.yaml
    - 操作員的命名空間規格。請勿編輯此檔案。
  • role_binding.yaml
    - 操作員的角色繫結規格。請勿編輯此檔案。
  • role.yaml
    - 操作員的角色規格。請勿編輯此檔案。
  • service_account.yaml
    - 操作員的服務帳戶規格。請勿編輯此檔案。
  • lb-secret.yaml
    - 用於預設 NSX-T 負載平衡器憑證的密碼。
  • nsx-secret.yaml
    - 用於對 NSX-T 進行憑證型驗證的密碼。這會用來取代
    configmap.yaml
    中的
    nsx_api_user
    nsx_api_password
  • operator.nsx.vmware.com_ncpinstalls_crd.yaml
    - 操作員擁有的客戶資源定義。
  • operator.nsx.vmware.com_v1_ncpinstall_cr.yaml
    - 操作員擁有的客戶資源。
下列
connfigmap.yaml
範例顯示基本組態。請參閱
deploy
資料夾中的
configmap.yaml
,以取得更多選項。您必須根據您的環境指定下列參數的值:
  • cluster
  • nsx_api_managers
  • nsx_api_user
  • nsx_api_password
  • external_ip_pools
  • tier0_gateway
  • overlay_tz
  • edge_cluster
  • apiserver_host_ip
  • apiserver_host_port
kind: ConfigMap 
metadata: 
  name: nsx-ncp-operator-config 
  namespace: nsx-system-operator 
data: 
  ncp.ini: | 
    [vc] 

    [coe] 

    # Container orchestrator adaptor to plug in. 
    adaptor = openshift4 

    # Specify cluster name. 
    cluster = ocp 

    [DEFAULT] 

    [nsx_v3] 
    policy_nsxapi = True 
    # Path to NSX client certificate file. If specified, the nsx_api_user and 
    # nsx_api_password options will be ignored. Must be specified along with 
    # nsx_api_private_key_file option 
    #nsx_api_cert_file = <None> 

    # Path to NSX client private key file. If specified, the nsx_api_user and 
    # nsx_api_password options will be ignored. Must be specified along with 
    # nsx_api_cert_file option 
    #nsx_api_private_key_file = <None> 

    nsx_api_managers = 10.114.209.10,10.114.209.11,10.114.209.12 

    nsx_api_user = admin 
    nsx_api_password = VMware1! 

    # Do not use in production 
    insecure = True 

    # Choices: ALL DENY <None> 
    log_firewall_traffic = DENY 

    external_ip_pools = 10.114.17.0/25 
    #top_tier_router = <None> 
    tier0_gateway = t0a 
    single_tier_topology = True 
    overlay_tz = 3efa070d-3870-4eb1-91b9-a44416637922 
    edge_cluster = 3088dc2b-d097-406e-b9de-7a161e8d0e47 

    [ha] 

    [k8s] 
    # Kubernetes API server IP address. 
    apiserver_host_ip = api-int.ocp.yasen.local 

    # Kubernetes API server port. 
    apiserver_host_port = 6443 

    client_token_file = /var/run/secrets/kubernetes.io/serviceaccount/token 

    # Choices: <None> allow_cluster allow_namespace 
    baseline_policy_type = allow_cluster 
    enable_multus = False 
    process_oc_network = False 
 
    [nsx_kube_proxy] 

    [nsx_node_agent] 

    ovs_bridge = br-int 

    # The OVS uplink OpenFlow port 
    ovs_uplink_port = ens192 

    [operator] 

    # The default certificate for HTTPS load balancing. 
    # Must be specified along with lb_priv_key option. 
    # Operator will create lb-secret for NCP based on these two options. 
    #lb_default_cert = <None> 

    # The private key for default certificate for HTTPS load balancing. 
    # Must be specified along with lb_default_cert option. 
    #lb_priv_key = <None>
operator.yaml
中,您必須在
env
區段中指定 NCP 映像的位置。
kind: Deployment
metadata: 
  name: nsx-ncp-operator 
  namespace: nsx-system-operator 
spec: 
  replicas: 1 
  selector: 
    matchLabels: 
      name: nsx-ncp-operator 
  template: 
    metadata: 
      labels: 
        name: nsx-ncp-operator 
    spec: 
      hostNetwork: true 
      serviceAccountName: nsx-ncp-operator 
      tolerations: 
      - effect: NoSchedule 
        key: node-role.kubernetes.io/master 
      - effect: NoSchedule 
        key: node.kubernetes.io/not-ready 
      containers: 
        - name: nsx-ncp-operator 
          # Replace this with the built image name 
          image: vmware/nsx-container-plugin-operator:latest 
          command: ["/bin/bash", "-c", "nsx-ncp-operator --zap-time-encoding=iso8601"] 
          imagePullPolicy: Always 
          env: 
            - name: POD_NAME 
              valueFrom: 
                fieldRef: 
                  fieldPath: metadata.name 
            - name: OPERATOR_NAME 
              value: "nsx-ncp-operator" 
            - name: NCP_IMAGE 
              value: "{NCP Image}"

使用主體身分識別將憑證型驗證設定為 NSX-T

在生產環境中,建議您不要使用
nsx_api_user
nsx_api_password
參數公開
configmap.yaml
中的管理員認證。下列步驟說明如何建立主體身分識別並允許 NCP 使用憑證進行驗證。
  1. 產生憑證和金鑰。
  2. 在 NSX Manager 中,導覽至
    系統
    使用者和角色
    ,然後按一下
    新增
    具有角色的主體身分識別
    。新增主體身分識別並貼上在步驟 1 中產生的憑證。
  3. nsx-secret.yaml
    中,新增 Base64 編碼的 crt 和金鑰值。
  4. 在 [nsx_v3] 區段下方的 configmap.yaml 中,設定憑證和金鑰檔案的位置:
    nsx_api_cert_file = /etc/nsx-ujo/nsx-cert/tls.crt
    nsx_api_private_key_file = /etc/nsx-ujo/nsx-cert/tls.key
附註:不支援在已執行啟動程序的叢集上變更驗證方法。

(選用) 設定預設 NSX-T 負載平衡器憑證

NSX-T 負載平衡器可以實作 OpenShift HTTPS 路由物件以及卸載 OCP HAProxy。若要執行此操作,則需要預設憑證。執行下列步驟以設定預設憑證:
  1. lb-secret.yaml
    中,新增 Base64 編碼的 crt 和金鑰值。
  2. [nsx_v3]
    區段下方的
    configmap.yaml
    中,設定憑證和金鑰的位置:
    lb_default_cert_path = /etc/nsx-ujo/lb-cert/tls.crt
    lb_priv_key_path = /etc/nsx-ujo/lb-cert/tls.key

(選用) 設定憑證式驗證至 NSX Manager

如果您在 ConfigMap 中設定
insecure
=
False
,則必須指定 NSX Manager 叢集中所有三個管理程式的憑證指紋。下列程序是如何執行此動作的範例。
將所有三個 NSX Manager 的憑證複製到檔案:
ssh -l admin 10.114.209.10 -f 'get certificate api' > nsx1.crt
ssh -l admin 10.114.209.11 -f 'get certificate api' > nsx2.crt
ssh -l admin 10.114.209.12 -f 'get certificate api' > nsx3.crt

NSX1=`openssl x509 -in nsx1.crt -fingerprint -noout|awk -F"=" '{print $2}'`
NSX2=`openssl x509 -in nsx2.crt -fingerprint -noout|awk -F"=" '{print $2}'`
NSX3=`openssl x509 -in nsx3.crt -fingerprint -noout|awk -F"=" '{print $2}'`
THUMB="$NSX1,$NSX2,$NSX3"
echo $THUMB
編輯 ConfigMap,並在
[nsx_v3]
區段中新增指紋:
oc edit cm nsx-ncp-operator-config -n nsx-system-operator

    nsx_api_managers = 10.114.209.10,10.114.209.11,10.114.209.12
    nsx_api_user = admin
    nsx_api_password = VMwareVMware1!
    insecure = False
    thumbprint = E0:A8:D6:06:88:B9:65:7D:FB:F8:14:CF:D5:E5:23:98:C9:43:10:71,A7:B0:26:B5:B2:F6:72:2B:39:86:19:84:E6:DD:AB:43:16:0E:CE:BD,52:9B:99:90:88:4C:9F:9B:83:5E:F7:AF:FC:60:06:50:BE:9E:32:08