create-service

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Create Service

创建服务

Generate Harness Service YAML and push to Harness via MCP.
生成Harness Service YAML并通过MCP推送到Harness。

Instructions

操作说明

  1. Detect service type from codebase (if source code is available) - Scan the project for deployment manifests to auto-select the correct
    serviceDefinition.type
    and manifest configuration:
    • k8s/
      ,
      kubernetes/
      ,
      manifests/
      with YAML files →
      Kubernetes
      with
      K8sManifest
    • kustomization.yaml
      Kubernetes
      with
      Kustomize
    • Chart.yaml
      ,
      charts/
      ,
      helm/
      NativeHelm
      with
      HelmChart
    • task-definition.json
      ECS
      with
      EcsTaskDefinition
    • serverless.yml
      /
      template.yaml
      (SAM) →
      ServerlessAwsLambda
    • function.json
      (Azure) →
      AzureWebApp
    • .NET
      + Windows →
      WinRm
    • Traditional app (JAR/WAR) without containers →
      Ssh
    • See
      create-pipeline/references/codebase-analysis.md
      Step 4 for the full decision tree
  2. Detect artifact source - Match Dockerfile registry references to artifact source type:
    • Docker Hub →
      DockerRegistry
    • *.dkr.ecr.*.amazonaws.com
      Ecr
    • gcr.io
      /
      *-docker.pkg.dev
      Gcr
    • *.azurecr.io
      Acr
  3. Confirm with user - Present detected service type, manifest type, and artifact source for confirmation
  4. Generate YAML following the structure below
  5. Create via MCP using
    harness_create
    with resource_type
    service
  1. 从代码库检测服务类型(若提供源代码)- 扫描项目中的部署清单,自动选择正确的
    serviceDefinition.type
    和清单配置:
    • 包含YAML文件的
      k8s/
      kubernetes/
      manifests/
      目录 → 采用
      Kubernetes
      类型并配置
      K8sManifest
    • kustomization.yaml
      文件 → 采用
      Kubernetes
      类型并配置
      Kustomize
    • Chart.yaml
      charts/
      helm/
      目录 → 采用
      NativeHelm
      类型并配置
      HelmChart
    • task-definition.json
      文件 → 采用
      ECS
      类型并配置
      EcsTaskDefinition
    • serverless.yml
      /
      template.yaml
      (SAM)→ 采用
      ServerlessAwsLambda
      类型
    • function.json
      (Azure)→ 采用
      AzureWebApp
      类型
    • .NET
      + Windows环境 → 采用
      WinRm
      类型
    • 无容器的传统应用(JAR/WAR)→ 采用
      Ssh
      类型
    • 完整决策树请参考
      create-pipeline/references/codebase-analysis.md
      第4步
  2. 检测制品源 - 匹配Dockerfile中的注册表引用以确定制品源类型:
    • Docker Hub →
      DockerRegistry
    • *.dkr.ecr.*.amazonaws.com
      Ecr
    • gcr.io
      /
      *-docker.pkg.dev
      Gcr
    • *.azurecr.io
      Acr
  3. 与用户确认 - 展示检测到的服务类型、清单类型和制品源,等待用户确认
  4. 生成YAML - 遵循下方的结构生成
  5. 通过MCP创建 - 使用
    harness_create
    工具,指定resource_type为
    service

Service Structure

服务结构

yaml
service:
  name: My Service
  identifier: my_service
  orgIdentifier: default
  projectIdentifier: my_project
  serviceDefinition:
    type: Kubernetes        # Kubernetes, NativeHelm, ECS, ServerlessAwsLambda, Ssh, WinRm, AzureWebApp, AzureFunction, CustomDeployment
    spec:
      artifacts:
        primary:
          primaryArtifactRef: docker_image
          sources:
            - identifier: docker_image
              type: DockerRegistry
              spec:
                connectorRef: dockerhub
                imagePath: myorg/myimage
                tag: <+input>
      manifests:
        - manifest:
            identifier: k8s_manifest
            type: K8sManifest
            spec:
              store:
                type: Github
                spec:
                  connectorRef: github_connector
                  repoName: my-manifests
                  branch: main
                  paths: [manifests/]
      variables:
        - name: replicas
          type: String
          value: "3"
yaml
service:
  name: My Service
  identifier: my_service
  orgIdentifier: default
  projectIdentifier: my_project
  serviceDefinition:
    type: Kubernetes        # Kubernetes, NativeHelm, ECS, ServerlessAwsLambda, Ssh, WinRm, AzureWebApp, AzureFunction, CustomDeployment
    spec:
      artifacts:
        primary:
          primaryArtifactRef: docker_image
          sources:
            - identifier: docker_image
              type: DockerRegistry
              spec:
                connectorRef: dockerhub
                imagePath: myorg/myimage
                tag: <+input>
      manifests:
        - manifest:
            identifier: k8s_manifest
            type: K8sManifest
            spec:
              store:
                type: Github
                spec:
                  connectorRef: github_connector
                  repoName: my-manifests
                  branch: main
                  paths: [manifests/]
      variables:
        - name: replicas
          type: String
          value: "3"

Deployment Types

部署类型

Kubernetes Service

Kubernetes服务

yaml
serviceDefinition:
  type: Kubernetes
  spec:
    artifacts:
      primary:
        primaryArtifactRef: main_image
        sources:
          - identifier: main_image
            type: DockerRegistry
            spec:
              connectorRef: dockerhub
              imagePath: myorg/api
              tag: <+input>
    manifests:
      - manifest:
          identifier: manifests
          type: K8sManifest
          spec:
            store:
              type: Github
              spec:
                connectorRef: github
                repoName: k8s-manifests
                branch: main
                paths: [deploy/]
yaml
serviceDefinition:
  type: Kubernetes
  spec:
    artifacts:
      primary:
        primaryArtifactRef: main_image
        sources:
          - identifier: main_image
            type: DockerRegistry
            spec:
              connectorRef: dockerhub
              imagePath: myorg/api
              tag: <+input>
    manifests:
      - manifest:
          identifier: manifests
          type: K8sManifest
          spec:
            store:
              type: Github
              spec:
                connectorRef: github
                repoName: k8s-manifests
                branch: main
                paths: [deploy/]

Helm Service

Helm服务

yaml
serviceDefinition:
  type: NativeHelm
  spec:
    artifacts:
      primary:
        primaryArtifactRef: chart
        sources:
          - identifier: chart
            type: DockerRegistry
            spec:
              connectorRef: dockerhub
              imagePath: myorg/api
              tag: <+input>
    manifests:
      - manifest:
          identifier: helm_chart
          type: HelmChart
          spec:
            store:
              type: Http
              spec:
                connectorRef: helm_repo
            chartName: my-chart
            chartVersion: <+input>
            helmVersion: V3
yaml
serviceDefinition:
  type: NativeHelm
  spec:
    artifacts:
      primary:
        primaryArtifactRef: chart
        sources:
          - identifier: chart
            type: DockerRegistry
            spec:
              connectorRef: dockerhub
              imagePath: myorg/api
              tag: <+input>
    manifests:
      - manifest:
          identifier: helm_chart
          type: HelmChart
          spec:
            store:
              type: Http
              spec:
                connectorRef: helm_repo
            chartName: my-chart
            chartVersion: <+input>
            helmVersion: V3

Kustomize Service

Kustomize服务

yaml
serviceDefinition:
  type: Kubernetes
  spec:
    artifacts:
      primary:
        primaryArtifactRef: main_image
        sources:
          - identifier: main_image
            type: DockerRegistry
            spec:
              connectorRef: dockerhub
              imagePath: myorg/api
              tag: <+input>
    manifests:
      - manifest:
          identifier: kustomize
          type: Kustomize
          spec:
            store:
              type: Github
              spec:
                connectorRef: github
                repoName: k8s-config
                branch: main
                folderPath: overlays/production
            pluginPath: ""
yaml
serviceDefinition:
  type: Kubernetes
  spec:
    artifacts:
      primary:
        primaryArtifactRef: main_image
        sources:
          - identifier: main_image
            type: DockerRegistry
            spec:
              connectorRef: dockerhub
              imagePath: myorg/api
              tag: <+input>
    manifests:
      - manifest:
          identifier: kustomize
          type: Kustomize
          spec:
            store:
              type: Github
              spec:
                connectorRef: github
                repoName: k8s-config
                branch: main
                folderPath: overlays/production
            pluginPath: ""

ECS Service

ECS服务

yaml
serviceDefinition:
  type: ECS
  spec:
    artifacts:
      primary:
        primaryArtifactRef: ecr_image
        sources:
          - identifier: ecr_image
            type: Ecr
            spec:
              connectorRef: aws_connector
              region: us-east-1
              imagePath: my-image
              tag: <+input>
    manifests:
      - manifest:
          identifier: task_def
          type: EcsTaskDefinition
          spec:
            store:
              type: Github
              spec:
                connectorRef: github
                repoName: ecs-config
                branch: main
                paths: [task-definition.json]
yaml
serviceDefinition:
  type: ECS
  spec:
    artifacts:
      primary:
        primaryArtifactRef: ecr_image
        sources:
          - identifier: ecr_image
            type: Ecr
            spec:
              connectorRef: aws_connector
              region: us-east-1
              imagePath: my-image
              tag: <+input>
    manifests:
      - manifest:
          identifier: task_def
          type: EcsTaskDefinition
          spec:
            store:
              type: Github
              spec:
                connectorRef: github
                repoName: ecs-config
                branch: main
                paths: [task-definition.json]

Serverless Lambda Service

Serverless Lambda服务

yaml
serviceDefinition:
  type: ServerlessAwsLambda
  spec:
    artifacts:
      primary:
        primaryArtifactRef: s3_artifact
        sources:
          - identifier: s3_artifact
            type: AmazonS3
            spec:
              connectorRef: aws_connector
              region: us-east-1
              bucketName: my-deployments
              filePath: serverless-app.zip
    manifests:
      - manifest:
          identifier: serverless_manifest
          type: ServerlessAwsLambda
          spec:
            store:
              type: Github
              spec:
                connectorRef: github
                repoName: serverless-config
                branch: main
                paths: [serverless.yml]
yaml
serviceDefinition:
  type: ServerlessAwsLambda
  spec:
    artifacts:
      primary:
        primaryArtifactRef: s3_artifact
        sources:
          - identifier: s3_artifact
            type: AmazonS3
            spec:
              connectorRef: aws_connector
              region: us-east-1
              bucketName: my-deployments
              filePath: serverless-app.zip
    manifests:
      - manifest:
          identifier: serverless_manifest
          type: ServerlessAwsLambda
          spec:
            store:
              type: Github
              spec:
                connectorRef: github
                repoName: serverless-config
                branch: main
                paths: [serverless.yml]

Artifact Source Types

制品源类型

  • DockerRegistry
    - Docker Hub (connectorRef, imagePath, tag)
  • Ecr
    - AWS ECR (connectorRef, region, imagePath, tag)
  • Gcr
    - Google GCR (connectorRef, registryHostname, imagePath, tag)
  • GoogleArtifactRegistry
    - Google Artifact Registry (connectorRef, region, repositoryName, package, version)
  • Acr
    - Azure ACR (connectorRef, subscriptionId, registry, repository, tag)
  • ArtifactoryRegistry
    - JFrog Artifactory (connectorRef, repository, artifactPath, repositoryFormat, tag)
  • Nexus3Registry
    - Nexus (connectorRef, repository, artifactPath, repositoryFormat, tag)
  • GithubPackageRegistry
    - GitHub Packages (connectorRef, packageType, org, packageName, version)
  • AmazonS3
    - S3 (connectorRef, region, bucketName, filePath)
  • GoogleCloudStorage
    - GCS (connectorRef, project, bucket, artifactPath)
  • CustomArtifact
    - Custom source (scripts, delegateSelectors, version)
  • DockerRegistry
    - Docker Hub(参数:connectorRef、imagePath、tag)
  • Ecr
    - AWS ECR(参数:connectorRef、region、imagePath、tag)
  • Gcr
    - Google GCR(参数:connectorRef、registryHostname、imagePath、tag)
  • GoogleArtifactRegistry
    - Google Artifact Registry(参数:connectorRef、region、repositoryName、package、version)
  • Acr
    - Azure ACR(参数:connectorRef、subscriptionId、registry、repository、tag)
  • ArtifactoryRegistry
    - JFrog Artifactory(参数:connectorRef、repository、artifactPath、repositoryFormat、tag)
  • Nexus3Registry
    - Nexus(参数:connectorRef、repository、artifactPath、repositoryFormat、tag)
  • GithubPackageRegistry
    - GitHub Packages(参数:connectorRef、packageType、org、packageName、version)
  • AmazonS3
    - S3(参数:connectorRef、region、bucketName、filePath)
  • GoogleCloudStorage
    - GCS(参数:connectorRef、project、bucket、artifactPath)
  • CustomArtifact
    - 自定义源(参数:scripts、delegateSelectors、version)

Creating via MCP

通过MCP创建

Call MCP tool: harness_create
Parameters:
  resource_type: "service"
  org_id: "<organization>"
  project_id: "<project>"
  body: <service YAML>
List existing services:
Call MCP tool: harness_list
Parameters:
  resource_type: "service"
  org_id: "<organization>"
  project_id: "<project>"
调用MCP工具:harness_create
参数:
  resource_type: "service"
  org_id: "<organization>"
  project_id: "<project>"
  body: <service YAML>
列出已有服务:
调用MCP工具:harness_list
参数:
  resource_type: "service"
  org_id: "<organization>"
  project_id: "<project>"

Examples

示例

  • "Create a K8s service with Docker Hub artifact" - Kubernetes type with DockerRegistry source
  • "Create a Helm service" - NativeHelm type with HelmChart manifest
  • "Create an ECS service with ECR" - ECS type with Ecr artifact source
  • "创建带Docker Hub制品的K8s服务" - Kubernetes类型搭配DockerRegistry源
  • "创建Helm服务" - NativeHelm类型搭配HelmChart清单
  • "创建带ECR的ECS服务" - ECS类型搭配Ecr制品源

Performance Notes

性能注意事项

  • Verify that referenced connectors exist before creating the service definition.
  • Ensure the deployment type matches the infrastructure type that will be used in the pipeline.
  • For artifact sources, confirm the image path and registry are accessible.
  • Quality of service configuration is more important than speed.
  • 创建服务定义前,确认引用的连接器已存在。
  • 确保部署类型与流水线中使用的基础设施类型匹配。
  • 对于制品源,确认镜像路径和注册表可访问。
  • 服务配置的质量比速度更重要。

Troubleshooting

故障排查

  • CONNECTOR_NOT_FOUND
    - Create connector first or fix connectorRef
  • DUPLICATE_IDENTIFIER
    - Service exists; use
    harness_update
  • Artifact tag
    <+input>
    means the tag is provided at runtime
  • CONNECTOR_NOT_FOUND
    - 先创建连接器或修正connectorRef
  • DUPLICATE_IDENTIFIER
    - 服务已存在;使用
    harness_update
    更新
  • 制品标签
    <+input>
    表示标签将在运行时提供