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

容器服务

复制全文
下载 pdf
CLB Ingress
为 CLB Ingress 配置 HTTPS 证书
复制全文
下载 pdf
为 CLB Ingress 配置 HTTPS 证书
为保证公网环境下的通信安全,业务使用 Ingress 暴露到公网时,通常使用 HTTPS 协议通信。本文为您介绍如何配置 HTTPS 协议的 CLB Ingress。​
注意​
配置 CLB Ingress 前,请务必仔细阅读 CLB Ingress 使用注意事项。​
证书管理​
容器服务 CLB Ingress 支持如下几种证书管理方式,主要区别如下表所示。​
​
对比项​
CLB 证书​
【推荐】证书中心证书​
证书存储方式​
CLB 存储。​
证书中心存储。​
证书发现方式​
通过证书 ID 发现。​
通过证书 ID 发现。​
更换证书方式​
手工更新。​
  • 手工更新。​
  • 证书中心更新,支持批量更新和部署。​
​
前提条件​
注意​
如需使用证书中心的证书,请首先登录您的火山引擎账号,然后单击 服务授权,并在弹出的页面中单击 立即授权,完成跨服务授权。​
  • (可选)若使用 YAML 配置,请确保已经在本地环境中安装 kubectl 工具,连接至目标集群。详情请参见 连接集群。​
操作步骤​
​
通过控制台配置
通过 kubectl 命令行配置
​
  1. 在集群列表页面,单击目标集群名称,进入集群配置管理页面。​
  1. 在左侧导航栏中,选择 服务与路由 > 路由规则,单击 创建路由规则,创建 CLB Ingress。​
  • 在 Ingress 类型 中,选择 传统型负载均衡 CLB。​
  • 在 监听配置 中,选择 HTTPS 协议,并在证书选择框中,单击 创建保密字典,配置证书。​
  • ​​​
  1. 配置保密字典的名称、证书来源,并选择对应的证书。单击 确定,完成保密字典配置。​
  • ​​​
  1. 回到路由规则配置页面,选择已配置证书,并完成路由规则中的其他参数配置。更多参数说明,请参见 通过控制台创建 CLB Ingress。​
  • ​​​
  1. 单击 确定,完成配置。​
​
结果验证​
查看配置​
执行以下命令,查看 ingress 配置。​
​
kubectl get ingress​
​
预期返回结果如下,表示 Ingress 服务创建成功,服务可以访问。​
​
NAME CLASS HOSTS ADDRESS PORTS AGE​
clb-ingress clb example.com 180.xxx.xxx.xxx 80,443 74s​
​
访问服务​
使用以下命令,通过域名访问服务。​
​
curl -H "Host: example.com" https://180.xxx.xxx.xxx --insecure​
​
注意​
  • 当您使用自签名证书时,可以使用-k或--insecure参数忽略证书的验证。​
  • 在生产环境中使用 TLS 证书时,建议您使用官方可信证书。使用自签名证书且忽略证书验证,可能导致您受到中间人攻击。​
预期输出如下,表示可以通过域名访问到后端服务。​
​
<!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>​
​
其他配置​
如何使用 OpenSSL 创建自签名证书​
注意​
自签名证书通常用于测试、联调或临时验证 HTTPS 配置,不建议直接用于生产环境。生产环境建议使用证书中心或受信任 CA 签发的 TLS 证书,以避免浏览器不信任证书或通信被中间人攻击。​
  1. 在本地环境中,访问 OpenSSL 官网,下载并安装 OpenSSL。​
  1. 执行以下命令,生成 4096 位的 RSA 私钥。​
  • ​
    openssl genrsa -out tls.key 4096​
    ​
  • 预期结果如下:​
  • ​
    Generating RSA private key, 4096 bit long modulus​
    ........+++++​
    ...+++++​
    e is 65537 (0x10001)​
    ​
  1. 执行以下命令,使用 RSA 私钥生成证书。​
  • ​
    openssl req -new -key tls.key -out tls.csr​
    ​
  • 预期结果如下,需要填写证书的相关信息,包括:国家、地区、组织名称、域名、电子邮件地址等。​
  • ​
    You are about to be asked to enter information that will be incorporated​
    into your certificate request.​
    What you are about to enter is what is called a Distinguished Name or a DN.​
    There are quite a few fields but you can leave some blank​
    For some fields there will be a default value,​
    If you enter '.', the field will be left blank.​
    -----​
    Country Name (2 letter code) []:CN # 2 位国家代码,例如 CN​
    State or Province Name (full name) []:Shanghai # 地区名称,例如 Shanghai​
    Locality Name (eg, city) []:Shanghai # 城市名称,例如 Shanghai​
    Organization Name (eg, company) []:vke # 组织名称​
    Organizational Unit Name (eg, section) []:vke # 组织中的单位名称​
    Common Name (eg, fully qualified host name) []:example.com # 该证书对应的域名​
    Email Address []:user@example.com # 电子邮件地址​
    ​
    Please enter the following 'extra' attributes​
    to be sent with your certificate request​
    A challenge password []:mypassword # 密码,可以为空​
    ​
  1. 执行以下命令,使用私钥对证书进行签名,有效期配置为 365 天。​
  • ​
    openssl x509 -req -in tls.csr -out tls.crt -signkey tls.key -days 365​
    ​
  1. 至此,完成创建 HTTPS 加密所需的私钥tls.key和证书tls.crt。​
​
​
​
最近更新时间:2026.08.03 21:12:31
这个页面对您有帮助吗?
有用
有用
无用
无用