使用 acme.sh 为 Kong 网关自动部署SSL证书

内容目录

注意:这里我们默认 kong 也是通过 Docker 进行安装的,并且拥有一个网络 kong_default.

安装 acme.sh

这里我们使用 Docker compose 进行安装。
示例文件如下,

version: "3.9"

volumes:
  acme.sh:

# 一定要添加到kong的网络中
networks:
  kong:
    name: kong_default
    external: true

services:
  acme.sh:
    container_name: acme.sh
    image: neilpang/acme.sh
    command: daemon
    restart: always
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    networks:
      - kong

证书生成与部署

  1. 注册账户

    docker exec acme.sh --register-account -m [email protected]
  2. 生成证书

    docker exec \
    -e DP_Id="<id>" \
    -e DP_Key="<key>" \
    acme.sh --issue --dns dns_dp -d example.com -d *.example.com

    这里我们使用的是 cloudflare DNS 的生成方式,其他的 DNS 服务商的生成方式可以参考acme.sh Wiki.

  3. 部署证书

    docker exec \
    -e KONG_URL="http://kong:8001" \
    acme.sh --deploy -d example.com --deploy-hook kong

    其中的 KONG_URL 代表 Kong Admin URL.

留下回复