計算巢支持使用FluxCD在ACK部署Helm Chart,本文介紹如何使用FluxCD在計算巢中進行Helm Chart的部署。
背景信息
計算巢對FluxCD進行部署Helm Chart的過程進行了封裝,封裝成了ROS公共模塊MODULE::ACS::ComputeNest::FluxOciHelmDeploy,MODULE::ACS::ComputeNest::FluxOciHelmDeploy模塊支持如下參數。
使用方法
HelmChartUrl支持傳入OCI格式的Chart倉庫地址,具體在計算巢的使用中,可以選擇使用計算巢Helm Chart部署物,也可以使用用戶自己的Chart倉庫,下面分別進行介紹。
使用Helm Chart部署物創建服務
使用Helm Chart部署物時,先要進行部署物上傳。詳細信息,請參見創建部署物。
登錄計算巢控制臺。
在左側導航欄中選擇我的服務,在我創建的服務區域下單擊創建新服務。
在創建新服務界面,配置服務信息。
此處只列舉使用Helm Chart部署物創建服務需要特別配置的內容。更多信息,請參見創建私有部署服務。
在模板內容中定義Helm Chart部署物關聯的標識位,模板內容的詳細信息,請參見服務模板示例。
計算巢提供了
{{ computenest::helmchart::xx }}
和{{ computenest::helm::dockerconfigjson }}
兩個偽參數,分別用來在模板中關聯Helm Chart部署物和拉取密鑰,并在部署時進行替換。{{ computenest::helmchart::xx }}
:Helm部署物占位符,替換成Helm Chart的完整地址。例如:oci://compute-nest-chart-registry.cn-hangzhou.cr.aliyuncs.com/15634578xxxxxxxx/wordpress:15.4.1。{{ computenest::helm::dockerconfigjson }}
:拉取Helm Chart倉庫的密鑰。
服務模板偽參數信息如下:
Resources: FluxHelmDeploy: Type: MODULE::ACS::ComputeNest::FluxOciHelmDeploy Version: v1 Properties: ClusterId: Ref: ClusterId ReleaseName: wordpress Namespace: wordpress HelmChartUrl: '{{ computenest::helmchart::test }}' DockerConfigJson: '{{ computenest::helm::dockerconfigjson }}' ChartValues: mariadb: primary: persistence: enabled: true storageClass: alicloud-disk-essd size: 20Gi persistence: enabled: false
在部署物關聯處,設置Helm關聯信息。
單擊創建服務。
使用用戶提供的Chart倉庫
登錄計算巢控制臺。
在左側導航欄中,選擇我的服務,在我創建的服務頁簽中,單擊創建新服務。
在創建新服務界面,配置服務信息。
此處只列舉使用用戶提供的Helm倉庫創建服務需要特別配置的內容。更多信息,請參見創建私有部署服務。
在模板內容處,填寫使用用戶提供的Chart倉庫,編寫模板內容。
對于本身就有Chart倉庫的用戶,可以直接使用自己的Chart倉庫,可以是公開倉庫,也可以是私有倉庫。
使用用戶提供的公開Chart倉庫的示例如下:
WordpressComputenestHelmApplication: Type: MODULE::ACS::ComputeNest::FluxOciHelmDeploy Version: v1 Properties: ClusterId: ClusterId HelmChartUrl: oci://registry-1.docker.io/bitnamicharts/wordpress:15.4.1 ChartValues: mariadb: primary: persistence: enabled: true storageClass: alicloud-disk-essd size: 100Gi persistence: enabled: false wordpressUsername: Ref: WordpressUsername wordpressPassword: Ref: WordpressPassword Namespace: Ref: 'ALIYUN::StackName' ReleaseName: wordpress
當提供的Chart倉庫為私有倉庫時,
DockerConfigJson
需要填寫Chart倉庫的拉取密鑰,生成Chart倉庫拉取密鑰的方式如下。kubectl create secret docker-registry SECRET_NAME \ --docker-server=SERVER_NAME \ --docker-username=USER_NAME \ --docker-password=Password kubectl get secret SECRET_NAME -o yaml
單擊創建服務。
服務模板示例
本示例為WordPress服務以Helm Chart方式部署到ACK上的服務模板。
ROSTemplateFormatVersion: '2015-09-01'
Description:
en: 新建ack部署wordpress
zh-cn: new ack deploy wordpress
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集群再進行部署
Label:
en: Wether create ack cluster
zh-cn: 是否新建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: null
Required: true
Label:
en: Kubernetes ClusterId
zh-cn: K8s集群ID
AssociationProperty: 'ALIYUN::CS::Cluster::ClusterId'
AssociationPropertyMetadata:
RegionId: '${RegionId}'
Visible:
Condition:
Fn::Equals:
- ${CreateAck}
- false
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
VpcId:
Type: String
Label:
en: VPC ID
zh-cn: 專有網絡VPC實例ID
Description:
en: >-
Please search the ID starting with (vpc-xxx) from console-Virtual
Private Cloud
zh-cn: 現有虛擬專有網絡的實例ID
Default: ''
AssociationProperty: 'ALIYUN::ECS::VPC::VPCId'
AssociationPropertyMetadata:
RegionId: '${RegionId}'
Visible:
Condition:
Fn::Equals:
- ${CreateAck}
- true
VSwitchId:
Type: String
Label:
en: VSwitch ID
zh-cn: 交換機實例ID
Description:
en: >-
Instance ID of existing business network switches, console-Virtual
Private Cloud-VSwitches under query
zh-cn: 現有業務網絡交換機的實例ID
Default: ''
AssociationProperty: 'ALIYUN::ECS::VSwitch::VSwitchId'
AssociationPropertyMetadata:
VpcId: '${VpcId}'
ZoneId: '${ZoneId}'
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
AckNetworkPlugin:
Type: String
Label:
en: ack plugin network
zh-cn: ack網絡插件
AllowedValues:
- Flannel
- Terway
AssociationPropertyMetadata:
Visible:
Condition:
Fn::Equals:
- ${CreateAck}
- true
Default: Flannel
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::And:
- Fn::Equals:
- ${CreateAck}
- true
- Fn::Equals:
- ${AckNetworkPlugin}
- Flannel
Default: 10.0.0.0/16
PodVswitchId:
Type: String
Label:
en: VSwitch ID
zh-cn: pod交換機實例ID
Description:
en: >-
Instance ID of existing business network switches, console-Virtual
Private Cloud-VSwitches under query
zh-cn: 建議選擇網段掩碼不大于 19 的虛擬交換機
Default: ''
AssociationProperty: 'ALIYUN::ECS::VSwitch::VSwitchId'
AssociationPropertyMetadata:
VpcId: '${VpcId}'
ZoneId: '${ZoneId}'
Visible:
Condition:
Fn::And:
- Fn::Equals:
- ${CreateAck}
- true
- Fn::Equals:
- ${AckNetworkPlugin}
- Terway
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
WordpressUsername:
Type: String
Label:
zh-cn: wordpress用戶名
en: wordpress username
Default: user
WordpressPassword:
NoEcho: true
Type: String
Label:
zh-cn: wordpress密碼
en: wordpress password
Conditions:
CreateAck:
Fn::Equals:
- true
- Ref: CreateAck
FlannelPluginCondition:
Fn::Equals:
- Ref: AckNetworkPlugin
- Flannel
TerwayPluginCondition:
Fn::Equals:
- Ref: AckNetworkPlugin
- Terway
Resources:
VpcsDataSource:
Type: DATASOURCE::VPC::Vpcs
Properties:
VpcIds:
- Ref: VpcId
EcsSecurityGroup:
Type: ALIYUN::ECS::SecurityGroup
Condition: CreateAck
Properties:
SecurityGroupName:
Ref: ALIYUN::StackName
VpcId:
Ref: VpcId
SecurityGroupEgress:
- PortRange: '-1/-1'
Priority: 1
IpProtocol: all
DestCidrIp: 0.0.0.0/0
NicType: intranet
SecurityGroupIngress:
Fn::If:
- FlannelPluginCondition
- - PortRange: '-1/-1'
Priority: 1
IpProtocol: all
SourceCidrIp:
Ref: PodCidr
Description: pod網絡訪問開放
NicType: intranet
- PortRange: '-1/-1'
Priority: 1
IpProtocol: all
SourceCidrIp:
Fn::Jq:
- First
- .[].CidrBlock
- 'Fn::GetAtt':
- VpcsDataSource
- Vpcs
Description: vpc網絡訪問開放
NicType: intranet
- PortRange: '-1/-1'
Priority: 1
IpProtocol: icmp
SourceCidrIp: 0.0.0.0/0
Description: icmp協議端口放開
NicType: intranet
- - PortRange: '-1/-1'
Priority: 1
IpProtocol: all
SourceCidrIp:
Fn::Jq:
- First
- .[].CidrBlock
- 'Fn::GetAtt':
- VpcsDataSource
- Vpcs
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: VSwitchId
VpcId:
Ref: VpcId
WorkerInstanceTypes:
- Ref: WorkerInstanceType
NumOfNodes: 3
ClusterSpec: ack.pro.small
ContainerCidr:
Fn::If:
- FlannelPluginCondition
- Ref: PodCidr
- Ref: ALIYUN::NoValue
ServiceCidr:
Ref: ServiceCidr
PodVswitchIds:
Fn::If:
- TerwayPluginCondition
- - Ref: PodVswitchId
- Ref: ALIYUN::NoValue
ZoneIds:
- Ref: ZoneId
SecurityGroupId:
Ref: EcsSecurityGroup
WorkerSystemDiskCategory:
Ref: WorkerSystemDiskCategory
WorkerSystemDiskSize:
Ref: WorkerSystemDiskSize
LoginPassword:
Ref: LoginPassword
SnatEntry: true
Addons:
Fn::If:
- FlannelPluginCondition
- - Name: flannel
Config: ''
- - Name: terway-eniip
Config: ''
WordpressComputenestHelmApplication:
Type: MODULE::ACS::ComputeNest::FluxOciHelmDeploy
Version: v1
Properties:
WaitUntil:
- Kind: Service
Name: wordpress
JsonPath: $.status.loadBalancer.ingress[0].ip
Operator: NotEmpty
FirstMatch: true
Timeout: 300
ClusterId:
Fn::If:
- CreateAck
- Fn::GetAtt:
- ManagedKubernetesCluster
- ClusterId
- Ref: ClusterId
HelmChartUrl: '{{ computenest::helmchart::wordpress }}'
DockerConfigJson: '{{ computenest::helm::dockerconfigjson }}'
ChartValues:
mariadb:
primary:
persistence:
enabled: true
storageClass: alicloud-disk-essd
size: 100Gi
persistence:
enabled: false
wordpressUsername:
Ref: WordpressUsername
wordpressPassword:
Ref: WordpressPassword
Namespace:
Ref: 'ALIYUN::StackName'
ReleaseName: wordpress
Outputs:
# 將公網ip做為http返回的地址顯示在控制臺
Endpoint:
Description:
zh-cn: 對外暴露的公網IP地址
en: Public IP Addresses
Value:
Fn::Sub:
- "http://${ServerAddress} \n http://${ServerAddress}/admin"
- ServerAddress:
Fn::Select:
- 0
- Fn::GetAtt:
- WordpressComputenestHelmApplication
- WaitUntilData
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
- VpcId
- VSwitchId
- LoginPassword
Label:
en: Basic Configuration
zh-cn: 基礎配置
- Parameters:
- WorkerInstanceType
- WorkerSystemDiskCategory
- WorkerSystemDiskSize
- AckNetworkPlugin
- PodCidr
- PodVswitchId
- ServiceCidr
Label:
en: Kubernetes
zh-cn: Kubernetes配置
- Parameters:
- WordpressUsername
- WordpressPassword
Label:
en: Wordpress Config
zh-cn: Wordpress配置