【问题标题】:SSL certificate configuration for Angular Application hosted using Docker & Azure Kubernetes (AKS)使用 Docker 和 Azure Kubernetes (AKS) 托管的 Angular 应用程序的 SSL 证书配置
【发布时间】:2021-01-09 14:36:40
【问题描述】:

我正在使用 Azure Kubernetes 来使用 Docker 容器托管 Angular Web 应用程序。 我已经使用 OpenSSL 命令创建了 SSL 证书。现在,我需要为我的 Web 应用程序配置 HTTPS 和 SSL 证书。

请帮助我如何设置这些?

这是我的 Docker 文件

FROM nginx:latest as nginx
RUN rm -rf /usr/share/nginx/html/*
COPY /dist/merch-insight/nginx.conf /etc/nginx/conf.d/nginx.conf
COPY /dist/merch-insight /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]

这是我的 nginx.conf 文件

server {
  server_name my-app;
  charset utf-8;
  sendfile on;
  root /usr/share/nginx/html;

  #Caches static assets
  location ~ ^/(assets|bower_components|scripts|styles|views) {
    expires     31d;
    add_header  Cache-Control public;
  }

  #Caches Bundles created by angular cli
  location ~* \.(?:bundle.js|bundle.css)$ {
    expires 1M;
    access_log off;
    add_header Cache-Control "public";
  }

  ##
  # Main file index.html sending not found locations to the main
  ##
  location / {
    expires -1;
    add_header Pragma "no-cache";
    add_header Cache-Control "no-store, no-cache, must-revalidate, post-check=0, pre-check=0";
    index index.html index.htm;
    try_files $uri $uri/ /index.html;
  }
}

这是我的 yaml 文件

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: apweb
    version: v1
  name: apweb
  namespace: default
spec:
  selector:
    matchLabels:
      run: apweb
  replicas: 2

  template:
    metadata:
      labels:
        run: apweb
    spec:
      containers:
      - name: apweb
        image: mycontainerregistry.azurecr.io/apweb:dev
        imagePullPolicy: Always
        ports:
        - containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
  labels:
    app: apweb
    version: v1
  name: apweb-service
  namespace: default
spec:
  type: LoadBalancer
  ports:
  - port: 80
    protocol: TCP
    targetPort: 80
    name: http-web
  selector:
    run: apweb

【问题讨论】:

    标签: docker ssl kubernetes https azure-aks


    【解决方案1】:

    在 k8s 中你可以使用 nginx 入口控制器(或其他入口选项)来配置TLS termination

    请看一下来自 nginx ingress documentation 的这个例子。

    Here 解释了如何为你的 TLS 证书生成 k8s secret。

    Here你可以找到完整的安装指南。

    【讨论】:

      猜你喜欢
      • 2020-08-16
      • 2016-11-20
      • 2014-09-25
      • 2022-07-01
      • 1970-01-01
      • 2021-05-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多