1.6. 从您自己的基础架构中卸载 OpenStack 上的集群

您可以删除在用户置备的基础架构上部署到 Red Hat OpenStack Platform(RHOSP)中的集群。

1.6.1. 先决条件

  • 已在您的机器上

    • 一个目录,您可以在其中创建文件以帮助您执行移除过程
    • Python 3

1.6.2. 下载 playbook 的依赖项

用于简化从用户置备的基础架构中移除过程的 Ansible playbook 需要几个 Python 模块。在您要进行这个操作的机器上添加模块的仓库,然后下载它们。

注意

这些说明假设您使用 Red Hat Enterprise Linux(RHEL)8。

先决条件

  • Python 3 已在您的机器上安装

流程

  1. 在命令行中添加软件仓库:

    1. 使用 Red Hat Subscription Manager 注册:

      $ sudo subscription-manager register # If not done already
    2. 获取最新的订阅数据:

      $ sudo subscription-manager attach --pool=$YOUR_POOLID # If not done already
    3. 禁用当前的软件仓库:

      $ sudo subscription-manager repos --disable=* # If not done already
    4. 添加所需的软件仓库:

      $ sudo subscription-manager repos \
        --enable=rhel-8-for-x86_64-baseos-rpms \
        --enable=openstack-16-tools-for-rhel-8-x86_64-rpms \
        --enable=ansible-2.9-for-rhel-8-x86_64-rpms \
        --enable=rhel-8-for-x86_64-appstream-rpms
  2. 安装模块:

    $ sudo yum install python3-openstackclient ansible python3-openstacksdk
  3. 确保 python 命令指向 python3:

    $ sudo alternatives --set python /usr/bin/python3

1.6.3. 在使用您自己的基础架构的 RHOSP 上移除集群

您可以在使用您自己的基础架构的 Red Hat OpenStack Platform(RHOSP)上删除 OpenShift Container Platform 集群。要快速完成移除过程,请创建并运行多个 Ansible playbook。

先决条件

  • Python 3 已在您的机器上安装
  • 下载"下载 playbook 依赖项"中的模块
流程

您可以还会有在安装 OpenShift Container Platform 时留下的 common.yamlinventory.yaml playbook。如果有,则可以跳过该流程的前两个步骤。

  1. 将以下内容插入到名为 common.yaml 的本地文件中:

    例 1.17. common.yaml Ansible playbook

    - hosts: localhost
      gather_facts: no
    
      vars_files:
      - metadata.json
    
      tasks:
      - name: 'Compute resource names'
        set_fact:
          cluster_id_tag: "openshiftClusterID={{ infraID }}"
          os_network: "{{ infraID }}-network"
          os_subnet: "{{ infraID }}-nodes"
          os_router: "{{ infraID }}-external-router"
          # Port names
          os_port_api: "{{ infraID }}-api-port"
          os_port_ingress: "{{ infraID }}-ingress-port"
          os_port_bootstrap: "{{ infraID }}-bootstrap-port"
          os_port_master: "{{ infraID }}-master-port"
          os_port_worker: "{{ infraID }}-worker-port"
          # Security groups names
          os_sg_master: "{{ infraID }}-master"
          os_sg_worker: "{{ infraID }}-worker"
          # Server names
          os_bootstrap_server_name: "{{ infraID }}-bootstrap"
          os_cp_server_name: "{{ infraID }}-master"
          os_cp_server_group_name: "{{ infraID }}-master"
          os_compute_server_name: "{{ infraID }}-worker"
          # Trunk names
          os_cp_trunk_name: "{{ infraID }}-master-trunk"
          os_compute_trunk_name: "{{ infraID }}-worker-trunk"
          # Subnet pool name
          subnet_pool: "{{ infraID }}-kuryr-pod-subnetpool"
          # Service network name
          os_svc_network: "{{ infraID }}-kuryr-service-network"
          # Service subnet name
          os_svc_subnet: "{{ infraID }}-kuryr-service-subnet"
          # Ignition files
          os_bootstrap_ignition: "{{ infraID }}-bootstrap-ignition.json"
  2. 将以下内容插入到名为 inventory.yaml 的本地文件中,并编辑值以匹配您自己的值:

    例 1.18. inventory.yaml Ansible playbook

    all:
      hosts:
        localhost:
          ansible_connection: local
          ansible_python_interpreter: "{{ansible_playbook_python}}"
    
          # User-provided values
          os_subnet_range: '10.0.0.0/16'
          os_flavor_master: 'm1.xlarge'
          os_flavor_worker: 'm1.large'
          os_image_rhcos: 'rhcos'
          os_external_network: 'external'
          # OpenShift API floating IP address
          os_api_fip: '203.0.113.23'
          # OpenShift Ingress floating IP address
          os_ingress_fip: '203.0.113.19'
          # Service subnet cidr
          svc_subnet_range: '172.30.0.0/16'
          os_svc_network_range: '172.30.0.0/15'
          # Subnet pool prefixes
          cluster_network_cidrs: '10.128.0.0/14'
          # Subnet pool prefix length
          host_prefix: '23'
          # Name of the SDN.
          # Possible values are OpenshiftSDN or Kuryr.
          os_networking_type: 'OpenshiftSDN'
    
          # Number of provisioned Control Plane nodes
          # 3 is the minimum number for a fully-functional cluster.
          os_cp_nodes_number: 3
    
          # Number of provisioned Compute nodes.
          # 3 is the minimum number for a fully-functional cluster.
          os_compute_nodes_number: 3
  3. 可选: 如果您的集群使用 Kuryr,将以下内容插入到名为 down-load-balancers.yaml 的本地文件中:

    例 1.19. down-load-balancers.yaml

    # Required Python packages:
    #
    # ansible
    # openstackcli
    # openstacksdk
    
    - import_playbook: common.yaml
    
    - hosts: all
      gather_facts: no
    
      tasks:
      - name: 'Get an auth token'
        os_auth:
        register: cloud
        when: os_networking_type == "Kuryr"
    
      - name: 'List octavia versions'
        uri:
          method: GET
          headers:
            X-Auth-Token: "{{ cloud.ansible_facts.auth_token }}"
            Content-Type: 'application/json'
          url: "{{ cloud.ansible_facts.service_catalog | selectattr('name', 'match', 'octavia') | first | json_query('endpoints') | selectattr('interface', 'match', 'public') | first | json_query('url') }}/"
        register: octavia_versions
        when: os_networking_type == "Kuryr"
    
      - set_fact:
          versions: "{{ octavia_versions.json.versions | selectattr('id', 'match', 'v2.5') | map(attribute='id') | list }}"
        when: os_networking_type == "Kuryr"
    
      - name: 'List tagged loadbalancers'
        uri:
          method: GET
          headers:
            X-Auth-Token: "{{ cloud.ansible_facts.auth_token }}"
          url: "{{ cloud.ansible_facts.service_catalog | selectattr('name', 'match', 'octavia') | first | json_query('endpoints') | selectattr('interface', 'match', 'public') | first | json_query('url') }}/v2.0/lbaas/loadbalancers?tags={{cluster_id_tag}}"
        when:
        - os_networking_type == "Kuryr"
        - versions | length > 0
        register: lbs_tagged
    
      # NOTE: Kuryr creates an Octavia load balancer
      # for each service present on the cluster. Let's make
      # sure to remove the resources generated.
      - name: 'Remove the cluster load balancers'
        command:
          cmd: "openstack loadbalancer delete --cascade {{ item.id }}"
        with_items: "{{ lbs_tagged.json.loadbalancers }}"
        when:
        - os_networking_type == "Kuryr"
        - versions | length > 0
        - '"PENDING" not in item.provisioning_status'
    
      - name: 'List loadbalancers tagged on description'
        uri:
          method: GET
          headers:
            X-Auth-Token: "{{ cloud.ansible_facts.auth_token }}"
          url: "{{ cloud.ansible_facts.service_catalog | selectattr('name', 'match', 'octavia') | first | json_query('endpoints') | selectattr('interface', 'match', 'public') | first | json_query('url') }}/v2.0/lbaas/loadbalancers?description={{cluster_id_tag}}"
        when:
        - os_networking_type == "Kuryr"
        - versions | length == 0
        register: lbs_description
    
      # NOTE: Kuryr creates an Octavia load balancer
      # for each service present on the cluster. Let's make
      # sure to remove the resources generated.
      - name: 'Remove the cluster load balancers'
        command:
          cmd: "openstack loadbalancer delete --cascade {{ item.id }}"
        with_items: "{{ lbs_description.json.loadbalancers }}"
        when:
        - os_networking_type == "Kuryr"
        - versions | length == 0
        - '"PENDING" not in item.provisioning_status'
  4. 将以下内容插入到名为 down-compute-nodes.yaml 的本地文件中:

    例 1.20. down-compute-nodes.yaml

    # Required Python packages:
    #
    # ansible
    # openstackclient
    # openstacksdk
    
    - import_playbook: common.yaml
    
    - hosts: all
      gather_facts: no
    
      tasks:
      - name: 'Remove the Compute servers'
        os_server:
          name: "{{ item.1 }}-{{ item.0 }}"
          state: absent
        with_indexed_items: "{{ [os_compute_server_name] * os_compute_nodes_number }}"
    
      - name: 'List the Compute trunks'
        command:
          cmd: "openstack network trunk list -c Name -f value"
        when: os_networking_type == "Kuryr"
        register: trunks
    
      - name: 'Remove the Compute trunks'
        command:
          cmd: "openstack network trunk delete {{ item.1 }}-{{ item.0 }}"
        when:
        - os_networking_type == "Kuryr"
        - (item.1|string + '-' + item.0|string) in trunks.stdout_lines|list
        with_indexed_items: "{{ [os_compute_trunk_name] * os_compute_nodes_number }}"
    
      - name: 'Remove the Compute ports'
        os_port:
          name: "{{ item.1 }}-{{ item.0 }}"
          state: absent
        with_indexed_items: "{{ [os_port_worker] * os_compute_nodes_number }}"
  5. 将以下内容插入到名为 down-control-plane.yaml 的本地文件中:

    例 1.21. down-control-plane.yaml

    # Required Python packages:
    #
    # ansible
    # openstackclient
    # openstacksdk
    
    - import_playbook: common.yaml
    
    - hosts: all
      gather_facts: no
    
      tasks:
      - name: 'Remove the Control Plane servers'
        os_server:
          name: "{{ item.1 }}-{{ item.0 }}"
          state: absent
        with_indexed_items: "{{ [os_cp_server_name] * os_cp_nodes_number }}"
    
      - name: 'Remove the Control Plane server group'
        os_server_group:
          name: "{{ os_cp_server_group_name }}"
          state: absent
    
      - name: 'List the Compute trunks'
        command:
          cmd: "openstack network trunk list -c Name -f value"
        when: os_networking_type == "Kuryr"
        register: trunks
    
      - name: 'Remove the Control Plane trunks'
        command:
          cmd: "openstack network trunk delete {{ item.1 }}-{{ item.0 }}"
        when:
        - os_networking_type == "Kuryr"
        - (item.1|string + '-' + item.0|string) in trunks.stdout_lines|list
        with_indexed_items: "{{ [os_cp_trunk_name] * os_cp_nodes_number }}"
    
      - name: 'Remove the Control Plane ports'
        os_port:
          name: "{{ item.1 }}-{{ item.0 }}"
          state: absent
        with_indexed_items: "{{ [os_port_master] * os_cp_nodes_number }}"
  6. 将以下内容插入到名为 down-bootstrap.yaml 的本地文件中:

    例 1.22. down-bootstrap.yaml

    # Required Python packages:
    #
    # ansible
    # openstacksdk
    
    - import_playbook: common.yaml
    
    - hosts: all
      gather_facts: no
    
      tasks:
      - name: 'Remove the bootstrap server'
        os_server:
          name: "{{ os_bootstrap_server_name }}"
          state: absent
          delete_fip: yes
    
      - name: 'Remove the bootstrap server port'
        os_port:
          name: "{{ os_port_bootstrap }}"
          state: absent
  7. 将以下内容插入到名为 down-network.yaml 的本地文件中:

    例 1.23. down-network.yaml

    # Required Python packages:
    #
    # ansible
    # openstackclient
    # openstacksdk
    
    - import_playbook: common.yaml
    
    - hosts: all
      gather_facts: no
    
      tasks:
      - name: 'List ports attatched to router'
        command:
          cmd: "openstack port list --device-owner=network:router_interface --tags {{ cluster_id_tag }} -f value -c id"
        register: router_ports
    
      - name: 'Remove the ports from router'
        command:
          cmd: "openstack router remove port {{ os_router }} {{ item.1}}"
        with_indexed_items: "{{ router_ports.stdout_lines }}"
    
      - name: 'List ha ports attached to router'
        command:
          cmd: "openstack port list --device-owner=network:ha_router_replicated_interface --tags {{ cluster_id_tag }} -f value -c id"
        register: ha_router_ports
    
      - name: 'Remove the ha ports from router'
        command:
          cmd: "openstack router remove port {{ os_router }} {{ item.1}}"
        with_indexed_items: "{{ ha_router_ports.stdout_lines }}"
    
      - name: 'List ports'
        command:
          cmd: "openstack port list --tags {{ cluster_id_tag }} -f value -c id "
        register: ports
    
      - name: 'Remove the cluster ports'
        command:
          cmd: "openstack port delete {{ item.1}}"
        with_indexed_items: "{{ ports.stdout_lines }}"
    
      - name: 'Remove the cluster router'
        os_router:
          name: "{{ os_router }}"
          state: absent
    
      - name: 'List cluster networks'
        command:
          cmd: "openstack network list --tags {{ cluster_id_tag }} -f value -c Name"
        register: networks
    
      - name: 'Remove the cluster networks'
        os_network:
          name: "{{ item.1}}"
          state: absent
        with_indexed_items: "{{ networks.stdout_lines }}"
    
      - name: 'List the cluster subnet pool'
        command:
          cmd: "openstack subnet pool list --name {{ subnet_pool }}"
        when: os_networking_type == "Kuryr"
        register: pods_subnet_pool
    
      - name: 'Remove the cluster subnet pool'
        command:
          cmd: "openstack subnet pool delete {{ subnet_pool }}"
        when:
        - os_networking_type == "Kuryr"
        - pods_subnet_pool.stdout != ""
  8. 将以下内容插入到名为 down-security-groups.yaml 的本地文件中:

    例 1.24. down-security-groups.yaml

    # Required Python packages:
    #
    # ansible
    # openstackclient
    # openstacksdk
    
    - import_playbook: common.yaml
    
    - hosts: all
      gather_facts: no
    
      tasks:
      - name: 'List security groups'
        command:
          cmd: "openstack security group list --tags {{ cluster_id_tag }} -f value -c ID"
        register: security_groups
    
      - name: 'Remove the cluster security groups'
        command:
          cmd: "openstack security group delete {{ item.1 }}"
        with_indexed_items: "{{ security_groups.stdout_lines }}"
  9. 在命令行中运行您创建的 playbook:

    $ ansible-playbook -i inventory.yaml  \
    	down-bootstrap.yaml      \
    	down-control-plane.yaml  \
    	down-compute-nodes.yaml  \
    	down-load-balancers.yaml \
    	down-network.yaml        \
    	down-security-groups.yaml
  10. 删除您为 OpenShift Container Platform 安装所做的任何 DNS 记录更改。

OpenShift Container Platform 被从您的基础架构中删除。