You can enable Internet access for an elastic container instance by associating it with an elastic IP address (EIP). Knative allows you to use an annotation to associate an existing EIP or create an EIP and associate the EIP with the elastic container instance on which a Knative Service is deployed. This topic describes how to use an annotation to associate an EIP with the elastic container instance on which a Knative Service is deployed.

Prerequisites

Background information

You can use one of the following methods to enable Internet access for an elastic container instance:
  • Associate an EIP with the elastic container instance: EIPs are public IP addresses that can be separately purchased and managed. You can enable Internet access for an elastic container instance by associating an EIP with the instance.
  • Associate an EIP with a NAT gateway: NAT gateways are Internet gateways that can be separately purchased. After you associate an EIP with a NAT gateway, the NAT gateway can provide Internet services for all elastic container instances that reside in the virtual private cloud (VPC) to which the NAT gateway belongs.

Knative allows you to enable Internet access for an elastic container instance only by associating an EIP with the elastic container instance. For more information about how to enable Internet access for an elastic container instance, see Enable Internet access.

Use an annotation to associate an EIP with an elastic container instance

You can use an annotation to associate an existing EIP or create an EIP and associate the EIP with the elastic container instance on which a Knative Service is deployed. The following table describes the annotations that you can use to configure the EIP.

Annotation Description
k8s.aliyun.com/eci-eip-instanceid Specifies an existing EIP that you want to associate.
k8s.aliyun.com/eci-with-eip Specifies whether to automatically create an EIP and associate the EIP with the elastic container instance.
k8s.aliyun.com/eip-bandwidth Specifies the maximum bandwidth for the EIP. Unit: Mbit/s. Default value: 5.
k8s.aliyun.com/eip-common-bandwidth-package-id Specifies the EIP bandwidth plan that you want to use.
k8s.aliyun.com/eip-isp Specifies the line type of the EIP.

Valid values:

  • BGP: BGP (Multi-ISP) line
  • BGP_PRO: BGP (Multi-ISP) Pro line
  • Example 1: Associate an existing EIP
    apiVersion: serving.knative.dev/v1
    kind: Service
    metadata:
      name: helloworld-go
    spec:
      template:
        metadata:
          labels:
            app: helloworld-go
          annotations:
            k8s.aliyun.com/eci-eip-instanceid: "eip-bp1q5n8cq4p7f6dzu****"    # Specify an existing EIP that you want to associate. 
        spec:
          containers:
            - image: registry.cn-hangzhou.aliyuncs.com/knative-sample/helloworld-go:73fbdd56
  • Example 2: Create and associate an EIP and specify the bandwidth limit of the EIP
    apiVersion: serving.knative.dev/v1
    kind: Service
    metadata:
      name: helloworld-go
    spec:
      template:
        metadata:
          labels:
            app: helloworld-go
          annotations:
            k8s.aliyun.com/eci-with-eip: "true"   # Create and associate an EIP. 
            k8s.aliyun.com/eip-bandwidth: "10"   # Specify the bandwidth limit of the EIP. 
        spec:
          containers:
            - image: registry.cn-hangzhou.aliyuncs.com/knative-sample/helloworld-go:73fbdd56
  • Example 3: Create and associate an EIP and associate an EIP bandwidth plan with the EIP
    apiVersion: serving.knative.dev/v1
    kind: Service
    metadata:
      name: helloworld-go
    spec:
      template:
        metadata:
          labels:
            app: helloworld-go
          annotations:
            k8s.aliyun.com/eci-with-eip: "true"   # Create and associate an EIP. 
            k8s.aliyun.com/eip-common-bandwidth-package-id: "cbwp-2zeukbj916scmj51m****"  # Associate an EIP bandwidth plan with the EIP. 
        spec:
          containers:
            - image: registry.cn-hangzhou.aliyuncs.com/knative-sample/helloworld-go:73fbdd56