通过Azure子域上的https访问Docker容器

作为一个实验,我尝试使用Azure容器服务和Kubernetes作为pipe弦乐器在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撰写文件创build了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访问服务? 在http s ://nginx-test.westus.cloudapp.azure.com/

我不认为我应该为httpsconfigurationnginx,因为证书不是我的。 我试过改变负载平衡器发送443stream量到端口80,但我收到一个超时错误。

我尝试将端口443映射到我的Kubernetes服务configuration中的端口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 Ingress controller
如果我们需要Kubernetes上的TLS终止,我们可以使用入口控制器,在Azure上我们可以使用Nginx Ingress controller
要将其归档,我们可以按照以下步骤操作:
1部署Nginx入口控制器
2创buildTLS证书
3部署testinghttp服务
4configurationTLS终止
有关在Azure上的Kubernetes上configuration用于TLS终止的Nginx入口控制器的更多信息,请参阅此博客 。

 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 

在这里输入图像说明

在这里输入图像说明