【问题标题】:Accessing docker container over https on Azure subdomain在 Azure 子域上通过 https 访问 docker 容器
【发布时间】:2017-12-02 09:23:43
【问题描述】:

作为一项实验,我尝试使用 Azure 容器服务和 Kubernetes 作为编排器在 Azure 上运行 docker 容器。我正在运行官方的 nginx 映像。以下是我正在采取的步骤:

az group create --name test-group --location westus az acs create --orchestrator-type=kubernetes --resource-group=test-group --name=k8s-cluster --generate-ssh-keys

我使用 Kompose 从 docker compose 文件创建了 Kubernetes 部署和服务文件。

部署文件 apiVersion: extensions/v1beta1 kind: Deployment metadata: annotations: kompose.service.type: LoadBalancer creationTimestamp: null labels: io.kompose.service: test name: test spec: replicas: 1 strategy: {} template: metadata: creationTimestamp: null labels: io.kompose.service: test spec: containers: - image: nginx:latest name: test ports: - containerPort: 80 resources: {} restartPolicy: Always status: {}

服务文件 apiVersion: v1 kind: Service metadata: annotations: kompose.service.type: LoadBalancer creationTimestamp: null labels: io.kompose.service: test name: test spec: ports: - name: "80" port: 80 targetPort: 80 selector: io.kompose.service: test type: LoadBalancer status: loadBalancer: {}

然后我可以开始一切:

kubectl create -f test-service.yaml,test-deployment.yaml

一旦一个 IP 被暴露,我就会为其分配一个 dns 前缀,这样我就可以像这样访问我正在运行的容器:http://nginx-test.westus.cloudapp.azure.com/。

我的问题是,如何使用 https 访问该服务?在 https://nginx-test.westus.cloudapp.azure.com/

我认为我不应该为 https 配置 nginx,因为证书不是我的。我尝试更改负载均衡器以将 443 流量发送到端口 80,但收到超时错误。

我尝试在我的 Kubernetes 服务配置中将端口 443 映射到端口 80。

ports: - name: "443" port: 443 targetPort: 80

但这会导致:

SSL peer was not expecting a handshake message it received. Error code: SSL_ERROR_HANDSHAKE_UNEXPECTED_ALERT

如何在https://nginx-test.westus.cloudapp.azure.com/查看我正在运行的容器?

【问题讨论】:

  • 好吧,你的 nginx 应该服务于 https,而不是 http
  • 那我需要绑定证书吗?
  • 显然你做到了
  • 证书属于微软。所以你是说我不能做我想做的事?
  • 哪个证书,我不明白?为什么你的 nginx 上的证书会属于 ms?

标签: azure docker https kubernetes


【解决方案1】:

如果我理解正确,我认为您正在寻找Nginx Ingress controller
如果我们需要在 Kubernetes 上终止 TLS,我们可以使用入口控制器,在 Azure 上我们可以使用Nginx Ingress controller
要存档此内容,我们可以按照以下步骤操作:
1 部署 Nginx 入口控制器
2 创建 TLS 证书
3 部署测试http服务
4 配置TLS终止
有关在 Azure 上的 Kubernetes 上为 TLS 终止配置 Nginx Ingress Controller 的更多信息,请参阅此blog

root@k8s-master-6F403744-0:~/ingress/examples/deployment/nginx# kubectl get services --namespace kube-system -w
NAME                   CLUSTER-IP     EXTERNAL-IP   PORT(S)   AGE
default-http-backend   10.0.113.185   <none>        80/TCP    42m
heapster   10.0.4.232   <none>    80/TCP    1h
kube-dns   10.0.0.10   <none>    53/UDP,53/TCP   1h
kubernetes-dashboard   10.0.237.125   <nodes>   80:32229/TCP   1h
nginx-ingress-ssl   10.0.92.57   40.71.37.243   443:30215/TCP   13m

【讨论】:

  • 我想在某些时候需要涉及自签名证书,这是无法解决的。我能够按照博客步骤进行设置。不幸的是,我在使用自签名证书时阻止访问该站点的环境中工作,因此我仍然无法从我的内部网络访问该站点。不过,我会将此答案标记为已接受。谢谢。
猜你喜欢
  • 2019-10-08
  • 1970-01-01
  • 1970-01-01
  • 2019-11-02
  • 2018-09-07
  • 1970-01-01
  • 2022-06-29
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多