文档

ROS Operator

更新时间:

ROS Operator是阿里云开发的一款Kubernetes Operator,集成了阿里云资源编排(ROS)帮助用户在ACK集群内定义、创建并管理阿里云资源。

前提条件

安装ROS Operator

添加ros-operator的自定义仓库

  1. 安装helm-acr插件。

    helm plugin install https://github.com/AliyunContainerService/helm-acr
  2. 添加ros-operator的自定义仓库。

    helm repo add ros-operator acr://aliyun-computenest-opensource-chart.cn-hangzhou.cr.aliyuncs.com/default/aliyun-ros-operator

安装插件

  • 安装对应版本插件。

    安装最新版本插件

    helm install ros-operator ros-operator/ros-operator

    安装指定版本插件

    helm install ros-operator ros-operator/ros-operator --version 0.0.2
  • 自定义变量值安装。

    您可以通过values.yml自定义所有的默认配置变量,比如镜像名称、标签、资源限制等,然后执行下列代码。

    helm install ros-operator -f your_values.yml ros-operator/ros-operator

(可选)删除插件

如果您不再需要使用ROS Operator插件,您可以选择执行下列代码删除插件。

helm delete ros-operator

管理ROS资源栈

创建资源栈

  1. 创建stack-sample.yml文件。

    touch stack-sample.yml
  2. 编译stack-sample.yml文件。

    您可以执行下列代码进入文件编译状态。

    vim stack-sample.yml

    在stack-sample.yml文件中输入下列模板示例,该示例通过templateContent内容里指定的ROS模板,创建了一个ECS实例以及实例所在的专有网络、交换机和实例的安全组。关于如何编写ROS模板创建阿里云资源,请参见模板编写快速入门

    apiVersion: batch.operator.ros.io/v1
    kind: RosStack
    metadata:
      name: sample-stack-ecs-instance-with-vpc
      labels:
        app: ecs_instance_with_vpc
    spec:
      templateContent: |
        ROSTemplateFormatVersion: '2015-09-01'
        Description: Creates VPC ECS instance
        Parameters:
          InstanceImageId:
            Default: centos_7
            Type: String
            Description:
              zh-cn: >-
                target='_blank'><font color='blue'>查找镜像</font></a></b>
              en: >-
                Image ID,see detail:<b><a
                href='https://www.alibabacloud.com/help/en/doc-detail/112977.html'
                target='_blank'><font color='blue'>Find the mirror</font></a></b>
            Label:
              zh-cn: 镜像
              en: Image
          SystemDiskCategory:
            Default: cloud_ssd
            Label:
              zh-cn: 系统盘类型
              en: System Disk Type
            Type: String
            Description:
              zh-cn: >-
                <font color='blue'><b>可选值:</b></font><br>[cloud_efficiency: <font
                color='green'>高效云盘</font>]<br>[cloud_ssd: <font
                color='green'>SSD云盘</font>]<br>[cloud_essd: <font
                color='green'>ESSD云盘</font>]<br>[cloud: <font
                color='green'>普通云盘</font>]<br>[ephemeral_ssd: <font
                color='green'>本地SSD盘</font>]
              en: >-
                <font color='blue'><b>Optional values:</b></font><br>[cloud_efficiency:
                <font color='green'>Efficient Cloud Disk</font>]<br>[cloud_ssd: <font
                color='green'>SSD Cloud Disk</font>]<br>[cloud_essd: <font
                color='green'>ESSD Cloud Disk</font>]<br>[cloud: <font
                color='green'>Cloud Disk</font>]<br>[ephemeral_ssd: <font
                color='green'>Local SSD Cloud Disk</font>]
            AllowedValues:
              - cloud_auto
              - cloud_efficiency
              - cloud_ssd
              - cloud
              - cloud_essd
              - ephemeral_ssd
          SystemDiskSize:
            Default: 20
            Type: Number
            Description:
              zh-cn: '系统盘大小, 取值范围:[20, 500], 单位:GB。'
              en: 'System disk size, range of values: 20-500, units: GB.'
            Label:
              zh-cn: 系统盘空间
              en: System Disk Space
          InstancePassword:
            Type: String
            Description:
              zh-cn: >-
                服务器登录密码,长度8-30,必须包含三项(大写字母、小写字母、数字、 ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/
                中的特殊符号)。
              en: >-
                Server login password, Length 8-30, must contain three(Capital letters,
                lowercase letters, numbers, ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ Special
                symbol in).
            MinLength: 8
            Label:
              zh-cn: 实例密码
              en: Instance Password
            NoEcho: true
            MaxLength: 30
            ConstraintDescription:
              zh-cn: '长度8-30,必须包含三项(大写字母、小写字母、数字、 ()`~!@#$%^&*_-+=|{}[]:;''<>,.?/ 中的特殊符号)。'
              en: >-
                Length 8-30, must contain three(Capital letters, lowercase letters,
                numbers, ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ Special symbol in).
          InstanceType:
            AssociationProperty: 'ALIYUN::ECS::Instance::InstanceType'
            AssociationPropertyMetadata:
              ZoneId: VSwitchZoneId
            Type: String
            Description:
              zh-cn: >-
                填写VSwitch可用区下可使用的规格;<br>通用规格:<font
                color='red'><b>ecs.c5.large</b></font><br>注:可用区可能不支持通用规格<br>
                target='_blank'><b><font color='blue'>实例规格族</font></a></b>
              en: >-
                Fill in the specifications that can be used under the VSwitch
                availability zone;</b></font><br>general specifications:<font
                color='red'><b>ecs.c5.large</b></font><br>note: a few zones do not
                support general specifications<br>see detail: <a
                href='https://www.alibabacloud.com/help/en/doc-detail/25378.html'
                target='_blank'><b><font color='blue'>Instance Specification
                Family</font></a></b>
            Label:
              zh-cn: 实例规格
              en: Instance Type
          VSwitchZoneId:
            AssociationProperty: 'ALIYUN::ECS::Instance:ZoneId'
            Type: String
            Description:
              zh-cn: >-
                可用区ID。<br><b>注: <font
                color='blue'>选择前请确认该可用区是否支持创建ECS资源的规格,建议与其他交换机可用区不同</font></b>
              en: >-
                Availability Zone ID.<br><b>note:<font color='blue'>before selecting,
                please confirm that the Availability Zone supports the specification of
                creating ECS resources,which is recommended to be different from other
                VSwitch Availability Zone</font></b>
            Label:
              zh-cn: 交换机可用区
              en: VSwitch Availability Zone
          InstancePublicIP:
            Default: false
            Type: Boolean
            Description:
              zh-cn: 是否分配公共IP。
              en: Whether to assign a common IP.
            Label:
              zh-cn: 分配公网IP
              en: Allocate Public IP
        Outputs:
          EcsInstanceId:
            Value:
              'Fn::GetAtt':
                - EcsInstance
                - InstanceId
        Resources:
          EcsSecurityGroup:
            Type: 'ALIYUN::ECS::SecurityGroup'
            Properties:
              SecurityGroupIngress:
                - Priority: 1
                  PortRange: '-1/-1'
                  NicType: intranet
                  SourceCidrIp: 0.0.0.0/0
                  IpProtocol: all
              VpcId:
                Ref: EcsVpc
              SecurityGroupEgress:
                - Priority: 1
                  PortRange: '-1/-1'
                  IpProtocol: all
                  NicType: intranet
                  DestCidrIp: 0.0.0.0/0
          EcsVSwitch:
            Type: 'ALIYUN::ECS::VSwitch'
            Properties:
              VpcId:
                Ref: EcsVpc
              CidrBlock: 192.168.0.0/24
              ZoneId:
                Ref: VSwitchZoneId
          EcsVpc:
            Type: 'ALIYUN::ECS::VPC'
            Properties:
              VpcName:
                'Fn::Join':
                  - '-'
                  - - StackId
                    - Ref: 'ALIYUN::StackId'
              CidrBlock: 192.168.0.0/16
          EcsInstance:
            Type: 'ALIYUN::ECS::Instance'
            Properties:
              SystemDiskCategory:
                Ref: SystemDiskCategory
              VpcId:
                Ref: EcsVpc
              SecurityGroupId:
                Ref: EcsSecurityGroup
              SystemDiskSize:
                Ref: SystemDiskSize
              ImageId:
                Ref: InstanceImageId
              AllocatePublicIP:
                Ref: InstancePublicIP
              VSwitchId:
                Ref: EcsVSwitch
              IoOptimized: optimized
              Password:
                Ref: InstancePassword
              InstanceType:
                Ref: InstanceType
              PrivateIpAddress: 192.168.0.1
      name: sample-stack-ecs-instance-with-vpc
      timeoutInMinutes: 3
      parameters:
        InstancePassword: Sample_Password
        InstanceType: ecs.g5.large
        VSwitchZoneId: cn-hangzhou-g
    重要
    • 此ROS模板中操作了ECS,VPC资源,请前往您的容器集群,在集群信息中单击 集群资源 -> Worker RAM 角色,然后单击新增授权,授予ROS、ECS、VPC权限。

    • metadata.name和spec.name需要保持一致。

    • spec内支持通过templateId,templateContent,templateURL三种方式指定ROS模板,请选择其中一种方式进行指定。

  3. 应用stack-sample.yml文件。

    执行下列代码ACK集群将会创建一个ROS Stack,并在阿里云创建对应的ROS资源栈。

    kubectl apply -f stack-sample.yml

    阿里云资源栈创建完成后,集群将会把资源栈的相关信息保存在ConfigMap中。ConfigMap中包含以下字段:

    字段

    描述

    RegionId

    cn-hangzhou

    地域。

    StackId

    b53e1b25-72c8-4356-b0f4-81d04972****

    资源栈ID。

    Status

    CREATE_COMPLETE

    资源栈状态。

    StatusReason

    Stack CREATE completed successfully

    资源栈状态原因。

    Outputs_EcsInstanceId

    i-2ze6gw6z2dfma1v7****

    创建的ECS实例ID。

    说明
    • 以Outputs为前缀的字段是资源栈的输出字段,其他字段为资源栈自身属性。

    • 建议您在使用Outputs字段前检查资源栈状态是否符合预期。

查看资源栈

您可以执行下列命令查看资源栈的详细信息,比如资源栈的状态以及资源栈关联的其他资源信息。

kubectl describe rosstacks sample-stack-ecs-instance-with-vpc

更新资源栈

  1. 更新stack-sample.yml文件。

    您可以执行下列命令编译stack-sample.yml文件,然后更新stack-sample.yml文件中的ROS模板。

    vim stack-sample.yml
  2. 应用stack-sample.yml文件。

    执行下列命令后触发更新流程,更新阿里云资源后,ConfigMap中的信息也会同步更新。

    kubectl apply -f stack-sample.yml

删除资源栈

当您不需要对应资源栈时,您可以执行下列命令删除对应资源栈,同时会触发删除阿里云资源以及对应的ConfigMap内容。

kubectl delete rosstack sample-stack-ecs-instance-with-vpc