Creating an Ingress

Function

This API is used to create an ingress.

If you want to display a created ingress on the Access Mode tab page of the workload details page on the CCI console, add labels for the ingress during creation. The labels set for the ingress must meet the following requirements:

  • The labels set for the Service must be the same as matchLabels settings under selector of the workload.
    For example, matchLabels is set as follows:
    "spec": {
            "replicas": 1,
            "selector": {
                "matchLabels": {
                    "app": "redis"
                }
            }

    labels must be set to "app": "redis" for the Service.

        "metadata": {
            "name": "redis",
            "labels": {
                "app": "redis"
            }
  • serviceName defined in the ingress must be the same as the name of the Service.

URI

POST /apis/extensions/v1beta1/namespaces/{namespace}/ingresses

Table 1 Path parameter

Parameter

Description

namespace

Object name and auth scope, such as for teams and projects.

Table 2 Query parameter

Parameter

Mandatory

Description

pretty

No

If 'true', then the output is pretty printed.

Request

Request parameters

For the description about request parameters, see Table 110.

Table 3 Data structure of the annotations field

Parameter

Mandatory

Type

Description

kubernetes.io/elb.id

Yes

String

ID of an enhanced load balancer.

kubernetes.io/elb.port

Yes

String

Port number of the enhanced load balancer.

kubernetes.io/elb.ip

No

String

IP address of the enhanced load balancer.

Example request

{
    "apiVersion": "extensions/v1beta1",
    "kind": "Ingress",
    "metadata": {
        "name": "redis",
        "labels": {
            "app": "redis"
        },
        "annotations": {
            "kubernetes.io/elb.id": "2d48d034-6046-48db-8bb2-53c67e8148b5",
            "kubernetes.io/elb.ip": "192.168.137.182",
            "kubernetes.io/elb.port": "6071"
        }
    },
    "spec": {
        "rules": [
            {
                "http": {
                    "paths": [
                        {
                            "path": "/",
                            "backend": {
                                "serviceName": "redis",
                                "servicePort": 8080
                            }
                        }
                    ]
                }
            }
        ]
    }
}

Response

Response parameters

For the description about response parameters, see Table 110.

Example response

{
    "kind": "Ingress",
    "apiVersion": "extensions/v1beta1",
    "metadata": {
        "name": "redis",
        "namespace": "namespace-test",
        "selfLink": "/apis/extensions/v1beta1/namespaces/namespace-test/ingresses/redis",
        "uid": "7f86c310-afe8-11e8-b6ef-f898ef6c78b4",
        "resourceVersion": "5161127",
        "generation": 1,
        "creationTimestamp": "2018-09-04T02:16:14Z",
        "labels": {
            "app": "redis",
            "isExternal": "true",
            "zone": "data"
        },
        "annotations": {
            "kubernetes.io/elb.id": "2d48d034-6046-48db-8bb2-53c67e8148b5",
            "kubernetes.io/elb.port": "6071"
        },
        "enable": true
    },
    "spec": {
        "rules": [
            {
                "http": {
                    "paths": [
                        {
                            "path": "/",
                            "backend": {
                                "serviceName": "redis",
                                "servicePort": 8080
                            }
                        }
                    ]
                }
            }
        ]
    },
    "status": {
        "loadBalancer": {}
    }
}

Status Code

Table 4 describes the status code of this API.

Table 4 Status code

Status Code

Description

201

Created

For more status codes, see Status Codes.