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. 在命令行中添加软件仓库:

    $ sudo subscription-manager register # If not done already
    $ sudo subscription-manager attach --pool=$YOUR_POOLID # If not done already
    $ sudo subscription-manager repos --disable=* # If not done already
    
    $ 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
    Copy to Clipboard Toggle word wrap
  2. 安装模块:

    $ sudo yum install python3-openstackclient ansible python3-openstacksdk
    Copy to Clipboard Toggle word wrap
  3. 确保 python 命令指向 python3:

    $ sudo alternatives --set python /usr/bin/python3
    Copy to Clipboard Toggle word wrap

您可以在使用您自己的基础架构的 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_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"
    Copy to Clipboard Toggle word wrap
  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
    Copy to Clipboard Toggle word wrap
  3. 可选: 如果您的集群使用 Kuryr,将以下内容插入到名为 down-06_load-balancers.yaml 的本地文件中:

    例 1.19. down-06_load-balancers.yaml

    # Required Python packages:
    #
    # ansible
    # openstackcli
    # openstacksdk
    
    - import_playbook: common.yaml
    
    - hosts: all
      gather_facts: no
    
      tasks:
      - name: 'Get a token for creating the server group'
        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'
    Copy to Clipboard Toggle word wrap
  4. 将以下内容插入到名为 down-05_compute-nodes.yaml 的本地文件中:

    例 1.20. down-05_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 }}"
    Copy to Clipboard Toggle word wrap
  5. 将以下内容插入到名为 down-04_control-plane.yaml 的本地文件中:

    例 1.21. down-04_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: '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 }}"
    Copy to Clipboard Toggle word wrap
  6. 将以下内容插入到名为 down-03_bootstrap.yaml 的本地文件中:

    例 1.22. down-03_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
    Copy to Clipboard Toggle word wrap
  7. 将以下内容插入到名为 down-02_network.yaml 的本地文件中:

    例 1.23. down-02_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 != ""
    Copy to Clipboard Toggle word wrap
  8. 将以下内容插入到名为 down-01_security-groups.yaml 的本地文件中:

    例 1.24. down-01_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 }}"
    Copy to Clipboard Toggle word wrap
  9. 在命令行中运行您创建的 playbook:

    $ ansible-playbook -i inventory.yaml  \
    	down-03_bootstrap.yaml      \
    	down-04_control-plane.yaml  \
    	down-05_compute-nodes.yaml  \
    	down-06_load-balancers.yaml \
    	down-02_network.yaml        \
    	down-01_security-groups.yaml
    Copy to Clipboard Toggle word wrap
  10. 删除您为 OpenShift Container Platform 安装所做的任何 DNS 记录更改。

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

返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2025 Red Hat