You need to enable JavaScript to run this app.
文档中心
容器服务

容器服务

复制全文
下载 pdf
ALB Ingress
使用 ALB Ingress 实现业务发布
复制全文
下载 pdf
使用 ALB Ingress 实现业务发布
ALB Ingress 基于火山引擎应用型负载均衡(Application Load Balancer,ALB),提供更加丰富的七层负载均衡能力。本文主要介绍使用 ALB Ingress 实现业务发布的操作方法和注意事项。​
注意​
配置 ALB Ingress 前,请务必仔细阅读 ALB Ingress 使用注意事项。​
操作步骤​
步骤一:创建 ALBInstance​
  1. 单击左侧导航栏中的 集群。​
  1. 在集群列表页面,单击目标集群。​
  1. 在左侧导航栏中,选择 工作负载 > 对象浏览器。 单击 使用 Yaml 创建,创建 ALB Instance。​
  • 在 类型 下拉菜单中选择 自定义。​
  • 在 Yaml 配置框内输入 Yaml 配置。​
  • ​
    apiVersion: loadbalancer.vke.volcengine.com/v1beta1​
    kind: ALBInstance​
    metadata:​
    name: alb # ALBInstance 资源名称​
    spec:​
    instanceID: "alb-2dgns526uiv41fi5********" # 填写已有 ALB 实例的 ID​
    listeners:​
    - protocol: "HTTP" # 监听器的协议​
    port: 80 # 监听器协议为 HTTP 时的监听端口​
    ​
说明​
本例中使用已有的 ALB 实例创建 ALBInstance,采用了最简单的配置方式。更多配置,请参见 通过 kubectl 创建 ALB Ingress。​
  1. 创建完成后,在 对象浏览器 页面,单击 albinstance,进入详情页面,查看创建的 ALBInstance 资源。​
步骤二:部署应用和服务​
  1. 创建工作负载的 YAML 文件。示例文件deployment-demo.yaml代码如下:​
  • ​
    apiVersion: apps/v1​
    kind: Deployment​
    metadata:​
    name: deployment-demo # 无状态负载名称​
    namespace: default # 无状态负载所在的命名空间​
    spec: ​
    replicas: 1 # 无状态负载的副本数​
    selector: ​
    matchLabels: ​
    app: nginx​
    template: ​
    metadata: ​
    labels: ​
    app: nginx​
    spec:​
    containers:​
    - name: nginx # 容器名称​
    image: nginx:latest # 容器镜像地址和 Tag​
    ports:​
    - containerPort: 80 # 容器开放的端口号​
    ​
  1. 执行以下命令,创建工作负载。​
  • ​
    kubectl apply -f deployment-demo.yaml​
    ​
  1. 创建服务的 YAML 文件。示例文件deployment-demo.yaml代码如下:​
  • ​
    apiVersion: v1​
    kind: Service​
    metadata:​
    name: service-demo # 服务名称​
    spec:​
    selector:​
    app: nginx # 通过标签选择器将服务与后段容器组(Pod)绑定。​
    ports:​
    - name: rule # 端口映射规则名称​
    protocol: TCP # 服务协议,支持 TCP 或 UDP​
    port: 80 # 服务端口​
    nodePort: 30000 # 节点端口,取值范围为 30000~32767。​
    targetPort: 80 # 容器端口,即工作负载对外提供服务的端口号或端口名称,例如:Nginx 开放的默认端口号为 80​
    type: NodePort # 服务的类型​
    ​
注意​
  • 当集群的容器网络模型为 Flannel 时,仅支持关联和选择 NodePort、LoadBalancer 类型的服务。​
  • 当集群的容器网络模型为 VPC-CNI 时:​
  • 若 Ingress 开启了 直通 Pod 模式,则支持关联和选择 NodePort、LoadBalancer、ClusterIP 类型的服务。​
  • 若 Ingress 未开启 直通 Pod 模式,则仅支持关联和选择 NodePort、LoadBalancer 类型的服务。​
  1. 执行以下命令,创建服务。​
  • ​
    kubectl apply -f service-demo.yaml​
    ​
步骤三: 创建 ALB Ingress​
  1. 创建路由规则(Ingress)的 YAML 文件,示例alb-ingress.yaml代码如下:​
  • ​
    apiVersion: networking.k8s.io/v1​
    kind: Ingress​
    metadata:​
    name: alb-ingress-demo # 路由规则的名称​
    namespace: default # 路由规则所属的命名空间​
    spec:​
    ingressClassName: alb # ALBInstance 的资源名称​
    rules:​
    - host: example.com # 需要对外提供访问的域名​
    http:​
    paths:​
    - pathType: Prefix # 路径匹配规则,默认为 Prefix(前缀匹配)​
    path: / # 请求匹配的路径​
    backend:​
    service:​
    name: service-demo # 需要对接的服务名称​
    port: ​
    number: 80 # 需要对接服务的端口号​
    ​
说明​
本例中使用最简单的方式创建 ALB Ingress。更多配置,请参见 通过 kubectl 创建 ALB Ingress。​
  1. 执行以下命令,创建 ALB Ingress。​
  • ​
    kubectl apply -f alb-ingress.yaml​
    ​
结果验证​
使用 ALB Ingress 中配置的域名访问服务。​
​
curl http://example.com​
​
预期结果如下,表示能够通过 ALB Ingress 访问到后端的服务。​
​
<!DOCTYPE html>​
<html>​
<head>​
<title>Welcome to nginx!</title>​
<style>​
html { color-scheme: light dark; }​
body { width: 35em; margin: 0 auto;​
font-family: Tahoma, Verdana, Arial, sans-serif; }​
</style>​
</head>​
<body>​
<h1>Welcome to nginx!</h1>​
<p>If you see this page, the nginx web server is successfully installed and​
working. Further configuration is required.</p>​
​
<p>For online documentation and support please refer to​
<a href="http://nginx.org/">nginx.org</a>.<br/>​
Commercial support is available at​
<a href="http://nginx.com/">nginx.com</a>.</p>​
​
<p><em>Thank you for using nginx.</em></p>​
</body>​
</html>​
​
​
最近更新时间:2026.04.07 14:19:46
这个页面对您有帮助吗?
有用
有用
无用
无用