为 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
。您必须根据您的环境指定以下参数的值:
  • 集群
  • 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 的基于证书的身份验证。

在生产环境中,建议不要在
configmap.yaml
中使用
nsx_api_user
nsx_api_password
参数公开管理员凭据。以下步骤介绍了如何创建主体身份,并允许 NCP 使用证书进行身份验证。
  1. 生成证书和密钥。
  2. 在 NSX Manager 中,导航到
    系统
    用户和角色
    ,然后单击
    添加
    主体身份和角色
    。添加主体身份,并粘贴在步骤 1 中生成的证书。
  3. nsx-secret.yaml
    中添加 Base64 编码的证书和密钥值。
  4. 在 configmap.yaml 中的 [nsx_v3] 部分下设置证书和密钥文件的位置:
    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 编码的证书和密钥值。
  2. configmap.yaml
    中的
    [nsx_v3]
    部分下设置证书和密钥的位置:
    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