All Products
Search
Document Center

Edge Security Acceleration:Get started with Edge Container

Last Updated:Dec 31, 2024

You can create an edge container to associate a containerized application with your website domain name. This way, users can access the containerized application from the domain name.

Important

Edge Container is in private preview and is provided free of charge only for customers who meet conditions. To use this service, contact us.

Create a container

Step 1: Create an application

An application is the basic unit for managing edge containers. You need to associate an Edge Security Acceleration (ESA)-covered domain name with an application to enable the application to provide external services.

  1. Log on to the ESA console.

  2. In the left-side navigation pane, choose Edge Computing > Edge Container. On the page that appears, click Create Application.

  3. Configure the Application Name and Service Port parameters, and click OK.

    Parameter

    Description

    Application Name

    The name must be 6 to 128 bytes in length and can contain lowercase letters, digits, and hyphens (-). It must start with a lowercase letter and end with a lowercase letter or digit.

    Service Port

    The port that is used to provide external services. Valid values: 1 to 65535.

    image

Step 2: Create a trigger

Edge containers use triggers to provide external services. You can associate the domain name of your website as a trigger with a containerized application. Then, clients can access the application from the domain name. ESA automatically adds a DNS record for the associated domain name.

  1. In the edge container list, click the ID of the application that you want to manage or click View Details in the Actions column.

  2. On the Triggers tab, click Add Domain Name.

  3. Enter the domain name that is used to access the container and click OK.

  4. Check the DNS record that ESA assigns for the associated domain name. Then, you can use this domain name to access your containerized application.

Step 3: Upload an image

An image is a containerized standard deliverable that is used to package an application and its dependencies. You can use a Dockerfile to build an application as a container image and upload the image to the image repository. Then, you can use the container image to start a container.

  1. Write code. The service port and probe settings in your code must be consistent with those you specified when creating a container.

package main

import (
	"bytes"
	"net/http"
	"strconv"
	"strings"

	"github.com/gorilla/mux"
)

func main() {
	router := mux.NewRouter()
	router.Path("/livez").HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
		rw.WriteHeader(http.StatusOK)
		rw.Write([]byte("OK"))
	})
	router.Path("/pi").HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
		nums := req.URL.Query()["n"]
		if len(nums) == 0 {
			rw.Write([]byte("3.14"))
			return
		}
		n, _ := strconv.Atoi(nums[0])
		rw.Write([]byte(formatPi(computePi(n))))
	})

	http.ListenAndServe("0.0.0.0:8081", router)
}

func formatPi(i, N int, pi []int) string {
	sb := new(bytes.Buffer)
	sb.WriteString("3.")
	for i++; i < N-2; i++ {
		s := strconv.Itoa(pi[i])
		s = strings.Repeat("0", 4-len(s)) + s
		sb.WriteString(s)
	}
	return sb.String()
}

func computePi(n int) (i, N int, pi []int) {
	N = n/4 + 3
	pi = make([]int, N)
	var j, k, p, q, r, t, u, v int
	a, b := [2]int{956, 80}, [2]int{57121, 25}
	s := 2
	M := 10000
	e := make([]int, N)
	for {
		s--
		if s+1 == 0 {
			break
		}
		k = s
		e[0] = a[s]
		i = N
		for {
			i--
			if i == 0 {
				break
			}
			e[i] = 0
		}
		q = 1
		for {
			j = i - 1
			if i >= N {
				break
			}
			r, v = 0, 0
			for {
				j += 1
				if j >= N {
					break
				}
				p = r*M + e[j]
				e[j] = p / b[s]
				t = v*M + e[j]
				u = t / q
				r = p % b[s]
				v = t % q
				if k != 0 {
					pi[j] += u
				} else {
					pi[j] -= u
				}
			}
			if e[i] == 0 {
				i++
			}
			q += 2
			if k != 0 {
				k = 0
			} else {
				k = 1
			}
		}
	}
	for {
		i--
		if i == 0 {
			break
		}
		t = pi[i] + s
		pi[i] = t % M
		if pi[i] < 0 {
			pi[i] += M
			s = t/M - 1
		} else {
			s = t / M
		}
	}
	return
}
  1. Write a Dockerfile to build an image and upload the image to the repository.

FROM alpine:latest
ENV TZ Asia/Shanghai
ADD lambda .
CMD ./lambda
export GOARCH="amd64" GOHOSTARCH="amd64" GOHOSTOS="linux" GOOS="linux"; go build -o lambda main.go
docker build -t *****.alibaba-inc.com/***/lambda:v0.1 .
docker push *****.alibaba-inc.com/***/lambda:v0.1

Step 4: Create a version

Creating versions is the basis for application release. You can configure different images, compute specifications, and probe methods for different versions.

Note

You are not allowed to release another version until the release percentage of a version reaches 100%. However, you can roll back a version during the process.

  1. In the edge container list, click the ID of the application that you want to manage or click View Details in the Actions column.

  2. On the Versions tab, click Create Version.

  3. Configure the parameters such as Version Name, Description, and Image Settings as prompted, and then click OK. The following table describes the parameters.

    Parameter

    Description

    Version Information

    Version Name

    The name must be 6 to 128 characters in length and can contain lowercase letters, digits, and hyphens (-). The name must start with a letter and end with a letter or digit. Version names must be unique.

    Description

    The description for the version.

    Image Settings

    Image Type

    Custom Image

    • If you select this option, you need to enter the address of the custom image.

    Container Registry Image

    • Container Registry: To select an image from this type of repository, make sure that you have activated Container Registry and uploaded an image to a repository in the Container Registry instance. For more information, see Create a Container Registry Enterprise Edition instance. You can then directly reference the Container Registry instance in ESA and authorize Edge Container to pull images from the instance.

    • Artifact Center: The cloud-native artifact center is released by Alibaba Cloud Container Registry. It provides secure and trusted base container images that are developed by Alibaba Cloud and OpenAnolis. The base images support multiple system architectures and include base OS images, base language images, and AI- and big data-related images that can be used in application containerization. The base images make your business containerization process more efficient and secure. For more information, see Overview of the artifact center.

    Container Settings

    Compute Specification

    You can select different specifications of CPU and memory based on your application scale. Valid values: 1C2G, 2C4G, 2C8G, 4C8G, 4C16G, 8C16G, and 8C32G. The fees vary with the selected specification.

    Temporary Disk Capacity

    The capacity of the temporary disk, which can be 512 MB, 10 GB, 20 GB, or 30 GB. The option 512 MB is free of charge.

    Startup Command

    This command is used to start the service process after the container is created.

    Probe Method

    Valid values: HTTP, TCP, and COMMAND.

    • HTTP

      • Probe URL: the probe URL, such as /test.

      • Probe Port: The port number ranges from 1 to 65535.

      • Probe Host: the Host header of the HTTP request.

      • SCHEME: Valid values are HTTP and HTTPS.

      • HEADER: the custom HTTP request header for the probe.

    • TCP

      • Probe Port: The port number ranges from 1 to 65535.

    • COMMAND

      • The custom script. If the script returns 0, the probe is successful. Otherwise, the probe fails.

    Probe Settings

    Probe Duration (Seconds)

    The duration between the time when a container is created and the time when the probe starts. This parameter is used in scenarios where the service process takes a long time to start.

    Timeout (Seconds)

    • The response timeout period when you set Probe Method to HTTP.

    • Indicates the TCP handshake timeout period when you set Probe Method to TCP.

    • Indicates the script running timeout period when you set Probe Method to COMMAND.

    Probe Interval (Seconds)

    The interval between two probes.

    Successes

    The number of consecutive successful probes required before a container is considered healthy and then restored.

    Failures

    The number of consecutive failed probes required before a container is considered unhealthy and then removed.

    Advanced Commands

    postStart

    The command that is used to initialize the system after the container is created but before the startup command is executed.

    preStop

    The command that is used for graceful shutdown of the application before the container is destroyed.

    Environment Variable

    Key

    The name of the environment variable.

    Value

    The value of the environment variable.

Step 5: Debug the version

We recommend that you debug the application version in the staging environment before you release it to the production environment. The staging environment and production environment are isolated from each other, where you can release different application versions.

  1. In the edge container list, click the ID of the application that you want to manage or click View Details in the Actions column.

  2. Click the Versions tab. In the Staging Environment section, click Release. In the dialog box that appears, select the version that you want to release and click Release.

    Note

    When the value of Status in the Staging Environment section becomes Released, the version has been released to the staging environment.

  3. After the release completes, click Instance Logon in the Staging Environment section to access the container. Debug the version in the code editor.

  4. In the Staging Environment section, click Instance Logs to view the logs of application startup and running.

    image

Step 6: Manage versions

Release a version

Edge container versions support canary releases. You can specify the release percentage when you release a version.

  1. In the edge container list, click the ID of the application or click View Details in the Actions column. On the page that appears, click the Versions tab.

  2. In the Production Environment section, click Release. In the dialog box that appears, select the version to be released and the release percentage.

  3. Click Release. When the value of Status in the Production Environment section becomes Released, the release is complete.image

    Note

    Edge containers support canary releases. When the release percentage reaches 100%, the version is fully deployed across all environments. At this point, this released version becomes the baseline version.

Roll back a version

You can click Roll Back to roll back a version that is released but its release percentage does not reach 100%. When the value of Status becomes Rolled back, the rollback is complete. The version after the rollback becomes the baseline version.