如何将 Helm 安装到 Kubernetes 集群并使用 Helm Chart 部署 CNF¶
概述¶
Tacker 支持 Helm Chart 作为 MCIOP(托管容器基础设施对象包)。
通过遵循以下步骤,用户可以在由 Mgmt Driver 部署的 Kubernetes 集群的主节点中安装和配置 Helm 环境,并且用户可以使用 Helm Chart 将 CNF 部署到部署的 Kubernetes 集群。
注意
此页面重点介绍原始文档中的更改。如果没有更改,请遵循原始步骤。
Kubernetes 集群和 Helm 部署¶
有关原始文档,请参阅 如何使用 Mgmt Driver 部署 Kubernetes 集群。
创建并上传 VNF 包¶
有关原始文档,请参阅 创建和上传 VNF 包。需要进行以下更改
修改 TOSCA.meta 文件以安装 Helm
添加 Helm 安装脚本
1. 目录结构¶
TOSCA-Metadata/TOSCA.meta¶
要在部署 Kubernetes 集群时安装 Helm,请将 helm 安装脚本信息添加到“TOSCA.meta”文件中。 “helm 安装脚本信息”的目标是以下 Scripts/ 添加的脚本。 示例如下。
TOSCA.meta
TOSCA-Meta-File-Version: 1.0
Created-by: Dummy User
CSAR-Version: 1.1
Entry-Definitions: Definitions/sample_kubernetes_top.vnfd.yaml
Name: Files/images/ubuntu-20.04-server-cloudimg-amd64.img
Content-Type: application/x-iso9066-image
Name: Scripts/install_k8s_cluster.sh
Content-Type: application/sh
Algorithm: SHA-256
Hash: ec6423c8d68ff19e0d44b1437eddefa410a5ed43a434fa51ed07bde5a6d06abe
Name: Scripts/install_helm.sh
Content-Type: application/sh
Algorithm: SHA-256
Hash: 4af332b05e3e85662d403208e1e6d82e5276cbcd3b82a3562d2e3eb80d1ef714
Name: Scripts/kubernetes_mgmt.py
Content-Type: text/x-python
Algorithm: SHA-256
Hash: bf651994ca7422aadeb0a12fed179f44ab709029c2eee9b2b9c7e8cbf339a66d
Scripts/¶
将以下 helm 安装脚本添加到 Scripts/。
$ ls Scripts/
install_helm.sh install_k8s_cluster.sh kubernetes_mgmt.py
部署 Kubernetes 集群¶
有关原始文档,请参阅 部署 Kubernetes 集群。需要进行以下更改
添加脚本路径信息以安装 Helm
1. 多主节点¶
1. 创建参数文件¶
将 helm_installation_script_path 作为 KeyValuePairs 添加到 部署 Kubernetes 集群的参数说明的定义中以安装 Helm。 随着此更改,json 文件也应包含上述 KeyValuePairs。
## Request parameter to install Helm
+-------------------------------+-----------------------------------------------+
| Attribute name | Parameter description |
+===============================+===============================================+
| helm_installation_script_path | File path of the script file to install Helm. |
+-------------------------------+-----------------------------------------------+
complex_kubernetes_param_file.json
{
"flavourId": "complex",
"vimConnectionInfo": [{
"id": "3cc2c4ff-525c-48b4-94c9-29247223322f",
"vimId": "8343f55f-6bdf-4c5f-91c4-f6dd145c616d",
"vimType": "openstack"
}],
"additionalParams": {
"k8s_cluster_installation_param": {
"script_path": "Scripts/install_k8s_cluster.sh",
"vim_name": "kubernetes_vim_complex_helm",
"master_node": {
"aspect_id": "master_instance",
"ssh_cp_name": "masterNode_CP1",
"nic_cp_name": "masterNode_CP1",
"username": "ubuntu",
"password": "ubuntu",
"cluster_cp_name": "vip_CP"
},
"worker_node": {
"aspect_id": "worker_instance",
"ssh_cp_name": "workerNode_CP2",
"nic_cp_name": "workerNode_CP2",
"username": "ubuntu",
"password": "ubuntu"
},
"proxy": {
"http_proxy": "http://user1:password1@host1:port1",
"https_proxy": "http://user1:password1@host1:port1",
"k8s_node_cidr": "10.10.0.0/24"
},
"helm_installation_script_path": "Scripts/install_helm.sh"
},
"lcm-operation-user-data": "./UserData/k8s_cluster_user_data.py",
"lcm-operation-user-data-class": "KubernetesClusterUserData"
},
"extVirtualLinks": [{
"id": "net0_master",
"resourceId": "9015848b-8b11-40bd-a918-01138313afa5",
"extCps": [{
"cpdId": "masterNode_CP1",
"cpConfig": [{
"linkPortId": "ed802cb7-15a4-4942-bf42-21511c888e21"
}]
}]
}, {
"id": "net0_worker",
"resourceId": "9015848b-8b11-40bd-a918-01138313afa5",
"extCps": [{
"cpdId": "workerNode_CP2",
"cpConfig": [{
"linkPortId": "ed802cb7-15a4-4942-bf42-21511c888e33"
}]
}]
}]
}
2. 检查实例化操作的结果¶
确保将带有额外字段的 VIM 添加到 vimConnectionInfo。
$ openstack vnflcm show 7131268c-68ca-4cbe-a881-de4fc339303e --column "VIM Connection Info"
+---------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------+
| Field | Value |
+---------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------+
| VIM Connection Info | [ |
| | { |
| | "id": "3cc2c4ff-525c-48b4-94c9-29247223322f", |
| | "vimId": "8343f55f-6bdf-4c5f-91c4-f6dd145c616d", |
| | "vimType": "openstack", |
| | "interfaceInfo": {}, |
| | "accessInfo": {}, |
| | "extra": {} |
| | }, |
| | { |
| | "id": "7829ce55-86cc-4d02-98a5-4d6ed9214bcb", |
| | "vimId": "690edc6b-7581-48d8-9ac9-910c2c3d7c02", |
| | "vimType": "kubernetes", |
| | "interfaceInfo": null, |
| | "accessInfo": { |
| | "authUrl": "https://10.10.0.91:16443" |
| | }, |
| | "extra": { |
| | "helmInfo": "{'masternode_ip': ['10.10.0.35', '10.10.0.63', '10.10.0.4'], 'masternode_username': 'ubuntu', 'masternode_password': 'ubuntu'}" |
| | } |
| | } |
| | ] |
+---------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------+
2. 单主节点¶
1. 创建参数文件¶
与“多主节点”的案例一样,将 helm_installation_script_path 作为 KeyValuePairs 添加到 部署 Kubernetes 集群的参数说明的定义中。 此外,您还应在 json 文件中包含 KeyValuePairs。
2. 检查实例化操作的结果¶
验证 Helm 是否已成功安装。 与“多主节点”的案例一样,确保将带有额外字段的 VIM 添加到 vimConnectionInfo。
ETSI NFV-SOL CNF 部署通过 Helm Chart¶
有关原始文档,请参阅 ETSI NFV-SOL CNF(容器化 VNF)部署。
准备 Kubernetes VIM¶
首先,您需要准备一台安装了 Kubernetes 和 Helm 的服务器。 如果服务器由 部署 Kubernetes 集群 部署,则可以跳过以下步骤 1 和 2。
1. 创建配置文件¶
您可以参考 创建配置文件 部分来创建配置文件。
2. 注册 Kubernetes VIM¶
您可以参考 注册 Kubernetes VIM 部分来注册 VIM。
3. 确认 VIM 状态¶
对于注册的 VIM 信息,请确认 VIM 存在并且状态为“ACTIVE”。
$ openstack vim list
+--------------------------------------+-----------------------------+----------------------------------+------------+------------+--------+
| ID | Name | Tenant_id | Type | Is Default | Status |
+--------------------------------------+-----------------------------+----------------------------------+------------+------------+--------+
| 690edc6b-7581-48d8-9ac9-910c2c3d7c02 | kubernetes_vim_complex_helm | 7e757a0cfea940dab100216036212a65 | kubernetes | False | ACTIVE |
| 8343f55f-6bdf-4c5f-91c4-f6dd145c616d | VIM0 | 7e757a0cfea940dab100216036212a65 | openstack | True | ACTIVE |
+--------------------------------------+-----------------------------+----------------------------------+------------+------------+--------+
准备 VNF 包¶
从原始部分 准备 VNF 包 需要进行以下更改
跳过 Kubernetes 对象文件创建
准备使用本地 Helm Chart 文件
验证 VNFD 约束
1. 创建 Kubernetes 对象文件¶
如果您使用 Helm,则不需要此步骤,因为部署使用 Helm Chart 而不是 deployment.yaml 文件。
2. 部署本地 Helm Chart 文件¶
当使用本地 Helm Chart 文件时,将要使用的 Chart 文件放在“Files/Kubernetes”中。 如果使用外部仓库,则不需要存储 Chart 文件。 请参阅 [1] 和 [2],了解如何创建和打包 Helm Chart 文件以及创建时需要注意的事项。
$ ls Files/kubernetes/
localhelm-0.1.0.tgz
3. 创建 TOSCA.meta 文件¶
有关原始文档,请参阅 3. 创建 TOSCA.meta 文件。 如果您使用本地 Helm Chart 文件,请输入与 Chart 文件相关的相关信息,而不是“deployment.yaml”。
$ cat TOSCA-Metadata/TOSCA.meta
TOSCA-Meta-File-Version: 1.0
Created-by: dummy_user
CSAR-Version: 1.1
Entry-Definitions: Definitions/sample_vnfd_top.yaml
Name: Files/kubernetes/localhelm-0.1.0.tgz
Content-Type: application/tar+gzip
Algorithm: SHA-256
Hash: 837fcfb73e5fc58572851a80a0143373d9d28ec37bd3bdf52c4d7d34b97592d5
4. 创建 VNFD¶
有关原始文档,请参阅 5. 创建 VNFD。
实例化 VNF¶
有关原始文档,请参阅 实例化 VNF。需要进行以下更改
将用于部署 CNF 的参数添加到 json 定义文件中
验证 CNF 部署结果
1. 设置 Helm Chart 的请求参数文件的值¶
有关原始文档,请参阅 1. 设置请求参数文件的值。 验证 VIM 的身份后,将以下参数添加到 json 定义文件中以通过 Helm Chart 部署 CNF。
## List of additional parameters for deploying CNF by Helm chart
+----------------------------+-----------+-----------------------------------------------------------+
| Attribute name | Data type | Parameter description |
+============================+===========+===========================================================+
|namespace | String | Namespace to deploy Kubernetes resources. |
| | | If absent, the value in Helm chart is used as default. |
+----------------------------+-----------+-----------------------------------------------------------+
|use_helm | Boolean | If "true", Kubernetes InfraDriver utilizes Helm client, |
| | | otherwise, Kubernetes Python client is used. |
| | | true: with Helm, false: without Helm |
+----------------------------+-----------+-----------------------------------------------------------+
|using_helm_install_param | Array | Parameters for the step related to Helm chart. |
| | | Shall be present if "use_helm" is "true". |
+----------------------------+-----------+-----------------------------------------------------------+
|> exthelmchart | Boolean | If true, Helm chart is not in VNF Package. |
| | | true: external Helm chart, false: in VNF Package |
+----------------------------+-----------+-----------------------------------------------------------+
|> helmchartfile_path | String | Path of Helm chart files in VNF Package. |
| | | Shall be present if "exthelmchart" is "false". |
| | | |
| | | Note: The "part of helmchartfile_path" that is noted |
| | | above must be unique for VIM. |
+----------------------------+-----------+-----------------------------------------------------------+
|> helmreleasename | String | Name of release as instance of Helm chart. |
| | | |
| | | Note: This parameter must be unique for VIM. |
+----------------------------+-----------+-----------------------------------------------------------+
|> helmparameter | Array | Parameters of KeyValuePairs, |
| | | which is specified during Helm installation. |
+----------------------------+-----------+-----------------------------------------------------------+
|> helmrepostitoryname | String | Helm repository name. |
| | | Shall be present if "exthelmchart" is "true". |
+----------------------------+-----------+-----------------------------------------------------------+
|> helmchartname | String | Helm chart name. |
| | | Shall be present if "exthelmchart" is "true". |
| | | |
| | | Note: This parameter must be unique for VIM. |
+----------------------------+-----------+-----------------------------------------------------------+
|> exthelmrepo_url | String | URL of external Helm repository. |
| | | Shall be present if "exthelmchart" is "true". |
| | | |
| | | Note: Don't specify a different exthelmrepo_url for an |
| | | already registered helmrepositoryname in VIM. |
+----------------------------+-----------+-----------------------------------------------------------+
|helm_replica_values | Dict | Parameters for the number of replicas for each aspectId |
| | | used during scale operation. |
| | | Shall be present if "use_helm" is "true". |
| | | |
| | | key: "aspectId" defined in VNFD and specified during |
| | | scale operation. |
| | | value: Parameter for the number of replicas defined in |
| | | Helm values. |
+----------------------------+-----------+-----------------------------------------------------------+
|vdu_mapping | Dict | Parameters for associating "VDU ID" with resource |
| | | information and helm install parameter. |
| | | "helmreleasename" in value shall be present if "use_helm" |
| | | is "true". |
| | | |
| | | key: "VDU ID" defined in VNFD. |
| | | value: Parameter for mapping resource information |
| | | corresponding to "VDU ID" for key like following: |
| | | "VDU1": { "kind": "Deployment", |
| | | "name": "resource-name", |
| | | "helmreleasename": "vdu1" } |
+----------------------------+-----------+-----------------------------------------------------------+
如果您使用存储在外部仓库中的 Chart 文件进行部署,请将 additionalParams.using_helm_install_param.exthelmchart 设置为 true 并设置其他参数。 以下是使用存储在外部仓库中的 Chart 文件进行部署的 json 定义文件的示例。
$ cat instance_helm.json
{
"flavourId": "simple",
"additionalParams": {
"namespace": "default",
"use_helm": "true",
"using_helm_install_param": [
{
"exthelmchart": "true",
"helmreleasename": "vdu1",
"helmparameter": [
"key1=value1",
"key2=value2"
],
"helmrepositoryname": "mychart",
"helmchartname": "externalhelm",
"exthelmrepo_url": "http://helmrepo.example.com/sample-charts"
}
],
"helm_replica_values": {
"vdu1_aspect": "replicaCount"
},
"vdu_mapping": {
"VDU1": {
"kind": "Deployment",
"name": "vdu1-externalhelm",
"helmreleasename": "vdu1"
}
}
},
"vimConnectionInfo": [
{
"id": "817954e4-c321-4a31-ae06-cedcc4ddb85c",
"vimId": "690edc6b-7581-48d8-9ac9-910c2c3d7c02",
"vimType": "kubernetes"
}
]
}
如果您使用本地 Helm Chart 文件进行部署,请将 additionalParams.using_helm_install_param.exthelmchart 设置为“false”并设置其他参数。 以下是使用本地 Helm Chart 文件进行部署的 json 定义文件的示例。
$ cat instance_helm.json
{
"flavourId": "simple",
"additionalParams": {
"namespace": "default",
"use_helm": "true",
"using_helm_install_param": [
{
"exthelmchart": "false",
"helmreleasename": "vdu1",
"helmparameter": [
"key1=value1",
"key2=value2"
],
"helmchartfile_path": "Files/kubernetes/localhelm-0.1.0.tgz"
}
],
"helm_replica_values": {
"vdu1_aspect": "replicaCount"
},
"vdu_mapping": {
"VDU1": {
"kind": "Deployment",
"name": "vdu1-localhelm",
"helmreleasename": "vdu1"
}
}
},
"vimConnectionInfo": [
{
"id": "817954e4-c321-4a31-ae06-cedcc4ddb85c",
"vimId": "690edc6b-7581-48d8-9ac9-910c2c3d7c02",
"vimType": "kubernetes"
}
]
}
2. 检查 Kubernetes 中的部署¶
有关原始文档,请参阅 4. 检查 Kubernetes 中的部署。 除了修改步骤之前的检查点之外,还要确保已部署 CNF 的 NAME 与 `additionalParams 中的 vdu_mapping.VDUxx.name 值匹配。
$ kubectl get deploy
NAME READY UP-TO-DATE AVAILABLE AGE
vdu1-localhelm 1/1 1 1 5m1s
3. 检查 Helm 中的部署¶
运行以下命令以验证是否通过 Helm Chart 部署。 如果 NAME 与“helmreleasename”匹配,则部署成功。
$ helm list --all
NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
vdu1 default 1 2021-09-10 09:26:02.091007332 +0000 UTC deployed localhelm-0.1.0 1.16.0