Updated on 2023-12-13 GMT+08:00

CCE.Service

Element Description

The CCE.Service element is used to deploy a Kubernetes resource object Service at the PaaS layer of HUAWEI CLOUD. By creating such an object, you can provide a unified entry address for a group of containerized applications with the same functions, and distribute requests in load balancing mode to backend containerized applications.

Element Properties

Table 1 Property Description

Property

Required

Descripiton

k8sManifest

Yes

Description file of the Kubernetes service

Type: dict

Value Description: Supports customization. You are not advised to change the name and labels under the metadata during an update.

Suggestion: For details, see the Kubernetes official guide at https://kubernetes.io/docs/concepts/services-networking/service.

clusterId

No

ID of the cluster to which the resource belongs

Type: HuaweiCloud.CCE.Cluster.Id

Value Description: Indicates the ID of an existing or new container cluster.

Value Constraint: The value must satisfy the UUID rule and support a maximum of 64 characters.

Suggestion: Connect to the cluster object and use the get_reference function to obtain the cluster ID. Leave it blank, and specify the ID on the AOS console when creating a stack. Enter the cluster ID. Specifically, log in to the CCE console, and choose Resource Management > Clusters. Click the target cluster, and you can then obtain its cluster ID.

namespace

No

Namespace of the cluster to which the resource belongs

Type: string

Value Description: Must be a valid namespace in the cluster, for example, default. If k8sManifest is defined, the namespace specified here will be overwritten by the namespace specified in k8sManifest (k8sManifest > metadata > namespace).

Value Constraint: The value must start with a letter. Only lowercase letters, digits, and hyphens (-) are allowed.

Suggestion: Customize the value based on the existing cluster or the cluster to be created.

Relationships Between Elements

Table 2 Relationship description

Description

Target

DependsOn

AOS.Batch

DependsOn

DCS.Redis

DependsOn

RDS.MySQL

DependsOn

CCE.Storage.EVS

DependsOn

OBS.Bucket

DependsOn

CCE.Storage.SFS

DependsOn

CCE.ConfigMap

DependsOn

CCE.Job

DependsOn

CCE.Storage.OBS

DependsOn

CCE.DaemonSet

DependsOn

CCE.Secret

DependsOn

CCE.Service

DependsOn

CCE.Ingress

DependsOn

CCE.StatefulSet

DependsOn

CCE.NodePool

DependsOn

CCE.Deployment

DependsOn

CCE.Pod

DependsOn

RDS.PostgreSQL

ContainedIn

CCE.Cluster

Connected

ULB.LoadBalancer

Relationship between CCE.Service and ULB.LoadBalancer:

  1. When compiling the service.yaml file, add kubernetes.io/elb.class: union to the annotations section in the metadata.
  1. loadBalancerIP in spec must be set to the private IP address of ULB, which can be obtained using get_attribute, for example, loadBalancerIP: {get_attribute:[ULB.LoadBalancer element name, vip_address]}.

    For details about how to create a service using a load balancer, see LoadBalancer.

Return Value

Property

Type

Description

IP

Array

ExternalIPs or LoadBalancerIP Value of a k8s service

Port

Array

NodePort Value of a k8s service

refName

string

Name of a k8s service

Blueprint Example

tosca_definitions_version: huaweicloud_tosca_version_1_0
inputs:
  labels:
    description: Application instance label, which must be the same as that specified by parameter selector
    label: Workload
    default: test
  deploymentName:
    description: Workload name 
    label: Workload
    default: deployment-test
  image:
    description: Application image address
    label: Workload
  ingressName:
    description: Ingress name
    label: Ingress information
    default: ingress-test
  host:
    description: Domain name information about the ingress host
    label: Ingress information
    default: test.com
  secretName:
    description: Secret name
    label: Ingress information
    type: HuaweiCloud.ECS.KeyPair.Name
  serviceName:
    description: Service name
    label: Network service
    default: service-test
  servicePort:
    description: Service port
    label: Network service
    default: 8888
    type: integer
  path:
    description: Application route
    label: Network service
    default: /test
  protocol:
    description: Service protocol, which must be TCP or UDP
    label: Network service
    default: TCP
  targetPort:
    description: Open service port of an application
    label: Network service
    default: 8888
    type: integer
node_templates:
  my-deployment:
    properties:
      k8sManifest:
        apiVersion: apps/v1
        kind: Deployment
        metadata:
          labels:
            app:
              get_input: labels
          name:
            get_input: deploymentName
        spec:
          replicas: 1
          selector:
            matchLabels:
              app:
                get_input: labels
          strategy:
            rollingUpdate:
              maxSurge: 0
              maxUnavailable: 1
            type: RollingUpdate
          template:
            metadata:
              labels:
                app:
                  get_input: labels
            spec:
              containers:
                - image:
                    get_input: image
                  imagePullPolicy: IfNotPresent
                  name: nginx
    requirements: []
    type: HuaweiCloud.CCE.Deployment
  my-ingress:
    properties:
      k8sManifest:
        apiVersion: extensions/v1beta1
        kind: Ingress
        metadata:
          annotations:
            ingress.beta.kubernetes.io/role: data
            ingress.kubernetes.io/secure-backends: 'false'
          labels:
            isExternal: 'true'
            zone: data
          name:
            get_input: ingressName
        spec:
          rules:
            - host:
                get_input: host
              http:
                paths:
                  - backend:
                      serviceName:
                        get_input: serviceName
                      servicePort:
                        get_input: servicePort
                    path:
                      get_input: path
          tls:
            - secretName:
                get_input: secretName
              hosts:
                - get_input: host
    requirements:
      - dependency:
          node: my-service
    type: HuaweiCloud.CCE.Ingress
  my-service:
    properties:
      k8sManifest:
        apiVersion: v1
        kind: Service
        metadata:
          name:
            get_input: serviceName
        spec:
          ports:
            - name:
                get_input: serviceName
              port:
                get_input: servicePort
              protocol:
                get_input: protocol
              targetPort:
                get_input: targetPort
          selector:
            app:
              get_input: labels
          sessionAffinity: ClientIP
          type: ClusterIP
    requirements:
      - dependency:
          node: my-deployment
    type: HuaweiCloud.CCE.Service