文档

Helm关联

更新时间:

录入服务模板时,若您需要使用已在计算巢发布的Helm Chart部署物,可以使用Helm关联功能。本文介绍设置Helm Chart部署物的相关操作。

背景信息

使用Helm关联功能时,需要您在服务模板中定义Helm Chart部署物关联的标识位,并在Helm Chart部署物关联中设置要关联的Helm Chart部署物,在创建服务实例时,计算巢会自动识别模板中的标识位,自动替换成Helm Chart包的拉取命令,拉取Helm Chart包并部署到对应的ACK集群中。

功能配置

  1. 在服务模板中定义Helm Chart部署物关联的标识位。

    在配置Helm Chart部署物功能前,需要先在模板中定义Helm Chart部署物标识位。Helm Chart部署物标识位的固定表达式为:{{ computenest::helmpull::xxx }}

    说明

    表达式中的xxx为任意单词,中间不可包含空格。

    此处以在ALIYUN::CS::ClusterApplication资源中定义Helm Chart部署物标识位{{ computenest::helmpull::test }}为例,展示模板中Helm Chart部署物关联的标识位信息。完整的模板示例,请参见模板示例

    ClusterHelmApplication:
        Type: ALIYUN::CS::ClusterHelmApplication
        DependsOn:
          - AddonsSleep
        Properties:
          ChartValues:
            ChartPullCmd:
              Fn::Base64Encode: "{{ computenest::helmpull::test }}"
            ChartValues:
              Ref: ChartValues
            ReleaseName:
              Ref: ALIYUN::StackName
            ChartNamespace:
              Ref: ALIYUN::StackName
            Kubeconfig:
              Fn::Base64Encode:
                Fn::GetAtt:
                  - ClusterUserKubeconfig
                  - Config
            CurlCli:
              Fn::Replace:
                - \&: \\&
                - Fn::GetAtt:
                    - WaitConditionHandle
                    - CurlCli
          ClusterId:
            Fn::If:
              - CreateAck
              - Fn::GetAtt:
                  - ManagedKubernetesCluster
                  - ClusterId
              - Ref: ClusterId
          ChartUrl: https://open-helm.oss-cn-hangzhou.aliyuncs.com/computenest-deploy-chart-0.1.0.tgz
          Namespace: default
          Name:
            Fn::Join:
              - '-' 
              - - 'deploy-chart'
                - Ref: ALIYUN::StackName
  2. 配置Helm关联。

    1. 在创建服务界面的部署物关联区域,单击设置Helm关联处的选择部署物

    2. 选择部署物(Helm关联)的弹窗中,选择需要关联的Helm Chart部署物和对应的版本。

      若您没有Helm Chart部署物,需先创建Helm Chart部署物后再选择。关于如何创建Helm Chart部署物,请参见创建部署物2024-04-10_18-07-43.png

  3. 单击确定2024-04-10_18-08-32.png

功能展示

服务创建完成后,当用户在创建服务实例时,计算巢会将模板中的内容根据部署物信息自动替换为镜像地址。{{ computenest::helmpull::test }} 会被替换为对应Helm Chart包的pull命令,用来下载Helm Chart包,替换命令如下:

14.png

用户在创建服务实例时,可以在ChartValues框中自定义Chart中可设置参数的值。

2023-08-28_16-56-33.png

结果展示

服务实例创建完成后,可以在服务实例详情页查看chart的使用说明信息。

15.png

模板示例

ROSTemplateFormatVersion: '2015-09-01'
Description:
  en: 新建ack部署
  zh-cn: new ack
Parameters:
  CreateAck:
    Type: Boolean
    Description:
      en: An existing ack cluster can be deployed by entering the cluster id. If there is no current cluster, create a new ack cluster before deploying
      zh-cn: 已有ack集群输入集群id即可部署,当前无集群先新建ack集群再进行部署
    Default: true
  ClusterId:
    Type: String
    Description:
      en: The ID of Kubernetes ClusterId in which application deployed.
      zh-cn: 部署应用程序的K8s集群ID
    AllowedPattern: '[0-9a-z]+$'
    Default: default
    Label:
      en: Kubernetes ClusterId
      zh-cn: K8s集群ID
    AssociationPropertyMetadata:
      Visible:
        Condition:
          Fn::Equals:
            - ${CreateAck}
            - false
  ChartValues:
    Type: Json
    Description:
      en: User-defined chart values, used when installing chart
      zh-cn: 用户自定义chart values,安装chart时使用, json格式
    Default: {}
  PayType:
    Type: String
    Label:
      en: ECS Instance Charge Type
      zh-cn: 付费类型
    Default: PostPaid
    AllowedValues:
      - PostPaid
      - PrePaid
    AssociationProperty: ChargeType
    AssociationPropertyMetadata:
      LocaleKey: InstanceChargeType
      Visible:
        Condition:
          Fn::Equals:
            - ${CreateAck}
            - true
  PayPeriodUnit:
    Type: String
    Label:
      en: Pay Period Unit
      zh-cn: 购买资源时长周期
    Default: Month
    AllowedValues:
      - Month
      - Year
    AssociationProperty: PayPeriodUnit
    AssociationPropertyMetadata:
      Visible:
        Condition:
          Fn::And:
            - Fn::Equals:
                - ${CreateAck}
                - true
            - Fn::Not:
                Fn::Equals:
                  - ${PayType}
                  - PostPaid
  PayPeriod:
    Type: Number
    Description:
      en: When the resource purchase duration is Month, the value of Period ranges from 1 to 9, 12, 24, 36, 48, or 60. <br><b><font color='red'> When ECS instance types are PrePaid valid </b></font>
      zh-cn: 当购买资源时长为Month时,Period取值:1~9 <br><b><font color='red'>当ECS实例类型为PrePaid有效</b></font>
    Label:
      en: Period
      zh-cn: 购买资源时长
    Default: 1
    AllowedValues:
      - 1
      - 2
      - 3
      - 4
      - 5
      - 6
      - 7
      - 8
      - 9
    AssociationProperty: PayPeriod
    AssociationPropertyMetadata:
      Visible:
        Condition:
          Fn::And:
            - Fn::Equals:
                - ${CreateAck}
                - true
            - Fn::Not:
                Fn::Equals:
                  - ${PayType}
                  - PostPaid
  ZoneId:
    Type: String
    AssociationProperty: ALIYUN::ECS::Instance:ZoneId
    Label:
      en: Zone ID
      zh-cn: 可用区
    Default: cn-hangzhou-h
    AssociationPropertyMetadata:
      Visible:
        Condition:
          Fn::Equals:
            - ${CreateAck}
            - true
  VpcCidrBlock:
    Type: String
    Label:
      en: VPC CIDR IPv4 Block
      zh-cn: 专有网络IPv4网段
    Description:
      zh-cn: VPC的ip地址段范围,<br>您可以使用以下的ip地址段或其子网:<br><font color='green'>[10.0.0.0/8]</font><br><font color='green'>[172.16.0.0/12]</font><br><font color='green'>[192.168.0.0/16]</font>
      en: 'The ip address range of the VPC in the CidrBlock form; <br>You can use the following ip address ranges and their subnets: <br><font color=''green''>[10.0.0.0/8]</font><br><font color=''green''>[172.16.0.0/12]</font><br><font color=''green''>[192.168.0.0/16]</font>'
    Default: 192.168.0.0/16
    AssociationProperty: ALIYUN::VPC::VPC::CidrBlock
    AssociationPropertyMetadata:
      Visible:
        Condition:
          Fn::Equals:
            - ${CreateAck}
            - true
  VSwitchCidrBlock:
    Type: String
    Label:
      en: VSwitch CIDR Block
      zh-cn: 交换机子网网段
    Description:
      zh-cn: 必须属于VPC的子网段。
      en: Must belong to the subnet segment of VPC.
    Default: 192.168.1.0/24
    AssociationProperty: ALIYUN::VPC::VSwitch::CidrBlock
    AssociationPropertyMetadata:
      VpcCidrBlock: VpcCidrBlock
      Visible:
        Condition:
          Fn::Equals:
            - ${CreateAck}
            - true
  LoginPassword:
    NoEcho: true
    Type: String
    Description:
      en: Server login password, Length 8-30, must contain three(Capital letters, lowercase letters, numbers, ()`~!@#$%^&*_-+=|{}[]:;<>,.?/ Special symbol in)
      zh-cn: 服务器登录密码,长度8-30,必须包含三项(大写字母、小写字母、数字、 ()`~!@#$%^&*_-+=|{}[]:;<>,.?/ 中的特殊符号)
    Label:
      en: Instance Password
      zh-cn: 实例密码
    ConstraintDescription:
      en: Length 8-30, must contain three(Capital letters, lowercase letters, numbers, ()`~!@#$%^&*_-+=|{}[]:;<>,.?/ Special symbol in)
      zh-cn: 长度8-30,必须包含三项(大写字母、小写字母、数字、 ()`~!@#$%^&*_-+=|{}[]:;<>,.?/ 中的特殊符号)
    AssociationProperty: ALIYUN::ECS::Instance::Password
    AssociationPropertyMetadata:
      Visible:
        Condition:
          Fn::Equals:
            - ${CreateAck}
            - true
    AllowedPattern: ^[a-zA-Z0-9-\(\)\`\~\!\@\#\$\%\^\&\*\_\-\+\=\|\{\}\[\]\:\;\<\>\,\.\?\/]*$
    MinLength: 8
    MaxLength: 30
    Default: computenest*12345
  WorkerInstanceType:
    Type: String
    Label:
      en: Worker Nodes Types
      zh-cn: Worker节点规格
    AssociationProperty: ALIYUN::ECS::Instance::InstanceType
    AssociationPropertyMetadata:
      ZoneId: ${ZoneId}
      Visible:
        Condition:
          Fn::Equals:
            - ${CreateAck}
            - true
    Default: ecs.g6.large
  WorkerSystemDiskCategory:
    Type: String
    AllowedValues:
      - cloud_efficiency
      - cloud_ssd
      - cloud_essd
    AssociationPropertyMetadata:
      LocaleKey: DiskCategory
      InstanceType: ${WorkerInstanceType}
      Visible:
        Condition:
          Fn::Equals:
            - ${CreateAck}
            - true
    Label:
      en: Worker System Disk Category
      zh-cn: Worker 系统盘磁盘类型
    Default: cloud_essd
  WorkerSystemDiskSize:
    Type: Number
    Label:
      en: Worker System Disk Size(GB)
      zh-cn: Worker节点系统盘大小(GB)
    MinValue: 1
    Default: 120
    AssociationPropertyMetadata:
      Visible:
        Condition:
          Fn::Equals:
            - ${CreateAck}
            - true
  PodCidr:
    Type: String
    Description:
      zh-cn: 请填写有效的私有网段,即以下网段及其子网:10.0.0.0/8,172.16-31.0.0/12-16,192.168.0.0/16<br>不能与 VPC 及 VPC 内已有 Kubernetes 集群使用的网段重复。<font color='blue'><b>创建成功后不能修改</b></font>
      en: 'Please fill in a valid private segment, i.e. the following segments and their subnets: 10.0.0.0/8, 172.16-31.0.0/12-16, 192.168.0.0/16<br> which cannot duplicate the network segments already used by clusters in VPC and VPC Kunetberes. <font color=''blue''><b>Cannot be modified after successful creation</b></font>'
    Label:
      zh-cn: Pod 网络 CIDR
      en: Pod Network CIDR
    AssociationProperty: ALIYUN::CS::ManagedKubernetesCluster::PodCidr
    AssociationPropertyMetadata:
      Visible:
        Condition:
          Fn::Equals:
            - ${CreateAck}
            - true
    Default: 10.0.0.0/16
  ServiceCidr:
    Type: String
    Description:
      zh-cn: 可选范围:10.0.0.0/16-24,172.16-31.0.0/16-24,192.168.0.0/16-24<br>不能与 VPC 及 VPC 内已有 Kubernetes 集群使用的网段重复。<font color='blue'><b>创建成功后不能修改</b></font>
      en: 'Optional range: 10.0.0.0/16-24, 172.16-31.0.0/16-24, 192.168.0.0/16-24<br> cannot duplicate segments already used by existing Kubernetes clusters in VPC and VPC.<font color=''blue''><b>Cannot be modified after successful creation</b></font>'
    Label:
      zh-cn: Service CIDR
      en: Service CIDR
    AssociationProperty: ALIYUN::CS::ManagedKubernetesCluster::ServiceCidr
    AssociationPropertyMetadata:
      Visible:
        Condition:
          Fn::Equals:
            - ${CreateAck}
            - true
    Default: 172.16.0.0/16
Conditions:
  CreateAck:
    Fn::Equals:
      - true
      - Ref: CreateAck
Resources:
  EcsVpc:
    Type: ALIYUN::ECS::VPC
    Condition: CreateAck
    Properties:
      VpcName:
        Ref: ALIYUN::StackName
      CidrBlock:
        Ref: VpcCidrBlock
  EcsVSwitch:
    Type: ALIYUN::ECS::VSwitch
    Condition: CreateAck
    Properties:
      VSwitchName:
        Ref: ALIYUN::StackName
      VpcId:
        Ref: EcsVpc
      ZoneId:
        Ref: ZoneId
      CidrBlock:
        Ref: VSwitchCidrBlock
  EcsSecurityGroup:
    Type: ALIYUN::ECS::SecurityGroup
    Condition: CreateAck
    Properties:
      SecurityGroupName:
        Ref: ALIYUN::StackName
      VpcId:
        Ref: EcsVpc
      SecurityGroupEgress:
        - PortRange: '-1/-1'
          Priority: 1
          IpProtocol: all
          DestCidrIp: 0.0.0.0/0
          NicType: intranet
      SecurityGroupIngress:
        - PortRange: '-1/-1'
          Priority: 1
          IpProtocol: all
          SourceCidrIp:
            Ref: PodCidr
          Description: pod网络访问开放
          NicType: intranet
        - PortRange: '-1/-1'
          Priority: 1
          IpProtocol: all
          SourceCidrIp:
            Ref: VpcCidrBlock
          Description: vpc网络访问开放
          NicType: intranet
        - PortRange: '-1/-1'
          Priority: 1
          IpProtocol: icmp
          SourceCidrIp: 0.0.0.0/0
          Description: icmp协议端口放开
          NicType: intranet
  ManagedKubernetesCluster:
    Type: ALIYUN::CS::ManagedKubernetesCluster
    Condition: CreateAck
    Properties:
      Name:
        Ref: ALIYUN::StackName
      ChargeType:
        Ref: PayType
      Period:
        Ref: PayPeriod
      PeriodUnit:
        Ref: PayPeriodUnit
      VSwitchIds:
        - Ref: EcsVSwitch
      VpcId:
        Ref: EcsVpc
      WorkerInstanceTypes:
        - Ref: WorkerInstanceType
      NumOfNodes: 3
      ClusterSpec: ack.pro.small
      ContainerCidr:
        Ref: PodCidr
      ServiceCidr:
        Ref: ServiceCidr
      ZoneIds:
        - Ref: ZoneId
      SecurityGroupId:
        Ref: EcsSecurityGroup
      WorkerSystemDiskCategory:
        Ref: WorkerSystemDiskCategory
      WorkerSystemDiskSize:
        Ref: WorkerSystemDiskSize
      LoginPassword:
        Ref: LoginPassword
      SnatEntry: true
      Addons:
        - Name: flannel
          Config: ''
  ClusterAddons:
    Type: ALIYUN::CS::ClusterAddons
    Properties:
      Addons:
        - Name: ack-helm-manager
      InstalledIgnore: true
      ClusterId:
        Fn::If:
          - CreateAck
          - Fn::GetAtt:
              - ManagedKubernetesCluster
              - ClusterId
          - Ref: ClusterId
  AddonsSleep:
    Type: ALIYUN::ROS::Sleep
    DependsOn:
      - ClusterAddons
    Properties:
      CreateDuration: 120
  WaitCondition:
    Type: ALIYUN::ROS::WaitCondition
    DependsOn:
      - ManagedKubernetesCluster
    Properties:
      Count: 1
      Handle:
        Ref: WaitConditionHandle
      Timeout: 300
  WaitConditionHandle:
    Type: ALIYUN::ROS::WaitConditionHandle
  ClusterUserKubeconfig:
    Type: DATASOURCE::CS::ClusterUserKubeconfig
    Properties:
      ClusterId:
        Fn::If:
          - CreateAck
          - Fn::GetAtt:
              - ManagedKubernetesCluster
              - ClusterId
          - Ref: ClusterId
  ClusterHelmApplication:
    Type: ALIYUN::CS::ClusterHelmApplication
    DependsOn:
      - AddonsSleep
    Properties:
      ChartValues:
        ChartPullCmd:
          Fn::Base64Encode: "{{ computenest::helmpull::test }}"
        ChartValues:
          Ref: ChartValues
        ReleaseName:
          Ref: ALIYUN::StackName
        ChartNamespace:
          Ref: ALIYUN::StackName
        Kubeconfig:
          Fn::Base64Encode:
            Fn::GetAtt:
              - ClusterUserKubeconfig
              - Config
        CurlCli:
          Fn::Replace:
            - \&: \\&
            - Fn::GetAtt:
                - WaitConditionHandle
                - CurlCli
      ClusterId:
        Fn::If:
          - CreateAck
          - Fn::GetAtt:
              - ManagedKubernetesCluster
              - ClusterId
          - Ref: ClusterId
      ChartUrl: https://open-helm.oss-cn-hangzhou.aliyuncs.com/computenest-deploy-chart-0.1.0.tgz
      Namespace: default
      Name:
        Fn::Join:
          - '-' 
          - - 'deploy-chart'
            - Ref: ALIYUN::StackName
Outputs:
  Endpoint:
    Description:
      zh-cn: ack集群链接
      en: Ack Cluster Addresses
    Value:
      Fn::Sub:
        - https://cs.console.aliyun.com/?spm=5176.181001.J_5253785160.4.75db4e26fb3rOG#/k8s/cluster/${ClusterId}/v2/workload/deployment/list?type=deployment&ns=${Namespace}
        - ClusterId:
            Fn::If:
              - CreateAck
              - Fn::GetAtt:
                  - ManagedKubernetesCluster
                  - ClusterId
              - Ref: ClusterId
          Namespace:
            Ref: ALIYUN::StackName
  ChartNotes:
    Description:
      zh-cn: chart说明
      en: Chart Notes
    Value:
      Fn::Base64Decode:
        Fn::GetJsonValue:
          - '1'
          - Fn::GetAtt:
              - WaitCondition
              - Data
Metadata:
  ALIYUN::ROS::Interface:
    ParameterGroups:
      - Parameters:
          - CreateAck
          - ClusterId
        Label:
          en: Whether create ack
          zh-cn: 是否新建ack集群
      - Parameters:
          - PayType
          - PayPeriodUnit
          - PayPeriod
        Label:
          en: PayType Configuration
          zh-cn: 付费类型配置
      - Parameters:
          - ZoneId
          - VpcCidrBlock
          - VSwitchCidrBlock
          - LoginPassword
        Label:
          en: Basic Configuration
          zh-cn: 基础配置
      - Parameters:
          - WorkerInstanceType
          - WorkerSystemDiskCategory
          - WorkerSystemDiskSize
          - ServiceCidr
          - PodCidr
        Label:
          en: Kubernetes
          zh-cn: Kubernetes配置
      - Parameters:
          - ChartValues
        Label:
          en: install chart
          zh-cn: 安装chart配置