create-infrastructure

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Create Infrastructure

创建基础设施

Generate Harness Infrastructure Definition YAML and push via MCP.
生成Harness基础设施定义YAML并通过MCP推送。

Instructions

操作步骤

  1. Identify infrastructure type - KubernetesDirect, KubernetesGcp (GKE), KubernetesAzure (AKS), ECS, or ServerlessAwsLambda
  2. Ensure prerequisites exist - The environment and cloud/cluster connector must be created first
  3. Generate YAML using the templates below, referencing the correct connector and environment
  4. Create via MCP using
    harness_create
    with resource_type
    infrastructure
  1. 确定基础设施类型 - KubernetesDirect、KubernetesGcp(GKE)、KubernetesAzure(AKS)、ECS或ServerlessAwsLambda
  2. 确认前提条件已存在 - 必须先创建环境和云/集群连接器
  3. 使用下方模板生成YAML,引用正确的连接器和环境
  4. 通过MCP创建,使用
    harness_create
    并设置resource_type为
    infrastructure

Infrastructure Types

基础设施类型

KubernetesDirect

KubernetesDirect

yaml
infrastructureDefinition:
  name: K8s Production
  identifier: k8s_prod
  orgIdentifier: default
  projectIdentifier: my_project
  environmentRef: prod
  deploymentType: Kubernetes
  type: KubernetesDirect
  spec:
    connectorRef: k8s_connector
    namespace: my-app-prod
    releaseName: release-<+INFRA_KEY_SHORT_ID>
  allowSimultaneousDeployments: false
yaml
infrastructureDefinition:
  name: K8s Production
  identifier: k8s_prod
  orgIdentifier: default
  projectIdentifier: my_project
  environmentRef: prod
  deploymentType: Kubernetes
  type: KubernetesDirect
  spec:
    connectorRef: k8s_connector
    namespace: my-app-prod
    releaseName: release-<+INFRA_KEY_SHORT_ID>
  allowSimultaneousDeployments: false

KubernetesGcp (GKE)

KubernetesGcp (GKE)

yaml
infrastructureDefinition:
  name: GKE Cluster
  identifier: gke_prod
  environmentRef: prod
  deploymentType: Kubernetes
  type: KubernetesGcp
  spec:
    connectorRef: gcp_connector
    cluster: my-gke-cluster
    namespace: my-app
    releaseName: release-<+INFRA_KEY_SHORT_ID>
yaml
infrastructureDefinition:
  name: GKE Cluster
  identifier: gke_prod
  environmentRef: prod
  deploymentType: Kubernetes
  type: KubernetesGcp
  spec:
    connectorRef: gcp_connector
    cluster: my-gke-cluster
    namespace: my-app
    releaseName: release-<+INFRA_KEY_SHORT_ID>

KubernetesAzure (AKS)

KubernetesAzure (AKS)

yaml
infrastructureDefinition:
  name: AKS Cluster
  identifier: aks_prod
  environmentRef: prod
  deploymentType: Kubernetes
  type: KubernetesAzure
  spec:
    connectorRef: azure_connector
    subscriptionId: <subscription_id>
    resourceGroup: my-rg
    cluster: my-aks-cluster
    namespace: my-app
    releaseName: release-<+INFRA_KEY_SHORT_ID>
yaml
infrastructureDefinition:
  name: AKS Cluster
  identifier: aks_prod
  environmentRef: prod
  deploymentType: Kubernetes
  type: KubernetesAzure
  spec:
    connectorRef: azure_connector
    subscriptionId: <subscription_id>
    resourceGroup: my-rg
    cluster: my-aks-cluster
    namespace: my-app
    releaseName: release-<+INFRA_KEY_SHORT_ID>

ECS

ECS

yaml
infrastructureDefinition:
  name: ECS Fargate
  identifier: ecs_prod
  environmentRef: prod
  deploymentType: ECS
  type: ECS
  spec:
    connectorRef: aws_connector
    region: us-east-1
    cluster: my-ecs-cluster
yaml
infrastructureDefinition:
  name: ECS Fargate
  identifier: ecs_prod
  environmentRef: prod
  deploymentType: ECS
  type: ECS
  spec:
    connectorRef: aws_connector
    region: us-east-1
    cluster: my-ecs-cluster

ServerlessAwsLambda

ServerlessAwsLambda

yaml
infrastructureDefinition:
  name: Lambda
  identifier: lambda_prod
  environmentRef: prod
  deploymentType: ServerlessAwsLambda
  type: ServerlessAwsLambda
  spec:
    connectorRef: aws_connector
    region: us-east-1
    stage: prod
yaml
infrastructureDefinition:
  name: Lambda
  identifier: lambda_prod
  environmentRef: prod
  deploymentType: ServerlessAwsLambda
  type: ServerlessAwsLambda
  spec:
    connectorRef: aws_connector
    region: us-east-1
    stage: prod

AzureWebApp

AzureWebApp

yaml
infrastructureDefinition:
  name: Azure Web App
  identifier: azure_webapp_prod
  environmentRef: prod
  deploymentType: AzureWebApp
  type: AzureWebApp
  spec:
    connectorRef: azure_connector
    subscriptionId: <subscription_id>
    resourceGroup: my-rg
yaml
infrastructureDefinition:
  name: Azure Web App
  identifier: azure_webapp_prod
  environmentRef: prod
  deploymentType: AzureWebApp
  type: AzureWebApp
  spec:
    connectorRef: azure_connector
    subscriptionId: <subscription_id>
    resourceGroup: my-rg

Asg (Auto Scaling Group)

Asg (Auto Scaling Group)

yaml
infrastructureDefinition:
  name: ASG Production
  identifier: asg_prod
  environmentRef: prod
  deploymentType: Asg
  type: Asg
  spec:
    connectorRef: aws_connector
    region: us-east-1
yaml
infrastructureDefinition:
  name: ASG Production
  identifier: asg_prod
  environmentRef: prod
  deploymentType: Asg
  type: Asg
  spec:
    connectorRef: aws_connector
    region: us-east-1

GoogleCloudFunctions

GoogleCloudFunctions

yaml
infrastructureDefinition:
  name: Cloud Functions
  identifier: gcf_prod
  environmentRef: prod
  deploymentType: GoogleCloudFunctions
  type: GoogleCloudFunctions
  spec:
    connectorRef: gcp_connector
    region: us-central1
    project: my-gcp-project
yaml
infrastructureDefinition:
  name: Cloud Functions
  identifier: gcf_prod
  environmentRef: prod
  deploymentType: GoogleCloudFunctions
  type: GoogleCloudFunctions
  spec:
    connectorRef: gcp_connector
    region: us-central1
    project: my-gcp-project

Pdc (Physical Data Center)

Pdc (Physical Data Center)

yaml
infrastructureDefinition:
  name: On-Prem Servers
  identifier: pdc_prod
  environmentRef: prod
  deploymentType: Ssh
  type: Pdc
  spec:
    connectorRef: pdc_connector
    hosts:
      - host1.example.com
      - host2.example.com
yaml
infrastructureDefinition:
  name: On-Prem Servers
  identifier: pdc_prod
  environmentRef: prod
  deploymentType: Ssh
  type: Pdc
  spec:
    connectorRef: pdc_connector
    hosts:
      - host1.example.com
      - host2.example.com

Creating via MCP

通过MCP创建

Call MCP tool: harness_create
Parameters:
  resource_type: "infrastructure"
  org_id: "<organization>"
  project_id: "<project>"
  body: <infrastructure YAML>
调用MCP工具: harness_create
参数:
  resource_type: "infrastructure"
  org_id: "<organization>"
  project_id: "<project>"
  body: <infrastructure YAML>

Examples

示例

  • "Create a K8s infrastructure for prod" - KubernetesDirect with prod namespace
  • "Set up GKE infrastructure" - KubernetesGcp with GCP connector
  • "Create ECS Fargate infrastructure" - ECS type with AWS connector
  • "Create Azure Web App infrastructure" - AzureWebApp type with subscription and resource group
  • "Set up on-prem infrastructure" - Pdc type with host list for SSH deployments
  • "为生产环境创建K8s基础设施" - 使用prod命名空间的KubernetesDirect类型
  • "搭建GKE基础设施" - 使用GCP连接器的KubernetesGcp类型
  • "创建ECS Fargate基础设施" - 使用AWS连接器的ECS类型
  • "创建Azure Web App基础设施" - 包含订阅和资源组的AzureWebApp类型
  • "搭建本地基础设施" - 包含SSH部署主机列表的Pdc类型

Performance Notes

性能注意事项

  • Verify the referenced connector and environment exist before creating the infrastructure definition.
  • Ensure namespace and cluster names are accurate — typos will cause deployment failures.
  • Use
    <+INFRA_KEY_SHORT_ID>
    in releaseName to guarantee uniqueness across deployments.
  • 创建基础设施定义前,请确认引用的连接器和环境已存在。
  • 确保命名空间和集群名称准确无误——拼写错误会导致部署失败。
  • 在releaseName中使用
    <+INFRA_KEY_SHORT_ID>
    以确保跨部署的唯一性。

Troubleshooting

故障排除

  • CONNECTOR_NOT_FOUND
    - Create the cloud/K8s connector first
  • ENVIRONMENT_NOT_FOUND
    - Create the environment first
  • releaseName
    must be unique per deployment; use
    <+INFRA_KEY_SHORT_ID>
  • deploymentType
    must match the service definition's type (e.g., Kubernetes service needs KubernetesDirect infra)
  • allowSimultaneousDeployments: false
    is the default; set to
    true
    only if concurrent deploys are safe
  • CONNECTOR_NOT_FOUND
    - 先创建云/K8s连接器
  • ENVIRONMENT_NOT_FOUND
    - 先创建环境
  • releaseName
    必须每个部署唯一;使用
    <+INFRA_KEY_SHORT_ID>
  • deploymentType
    必须与服务定义的类型匹配(例如,Kubernetes服务需要KubernetesDirect基础设施)
  • allowSimultaneousDeployments: false
    是默认设置;仅当并发部署安全时才设置为
    true