Kubernetes入口将http重定向到https [英] Kubernetes ingress redirects http to https
问题描述
我需要社区的帮助,我对kubernetes还是很陌生.
I need some help from the community, I'm pretty new to kubernetes.
我需要在"deployment.yaml"中定义的主机的URL.文件,以使用任何技术将http从重定向到https.接下来,我将把基础结构保留为我拥有的代码.
I need the URL of my host defined in the "deployment.yaml" file to redirect from http to https using whatever technique. Next I am going to leave the infrastructure as the code I have.
Deployment.yaml:
apiVersion: apps/v1
kind: Deployment
metadata:
name: web
namespace: default
spec:
selector:
matchLabels:
run: web
template:
metadata:
labels:
run: web
spec:
containers:
- image: gcr.io/google-samples/hello-app:1.0
imagePullPolicy: Always
name: web
ports:
- containerPort: 8080
protocol: TCP
service.yaml:
apiVersion: v1
kind: Service
metadata:
name: web
namespace: default
spec:
ports:
- port: 8080
protocol: TCP
targetPort: 8080
name: web
selector:
run: web
type: NodePort
很明显,我还为https创建了ssl证书.为此,我创建了一个由google管理的证书,其文件为" managedcertificate.yaml ":
I have also created an ssl certificate for https obviously. For this I have created a certificate managed by google with the file "managedcertificate.yaml":
apiVersion: networking.gke.io/v1beta2
kind: ManagedCertificate
metadata:
name: certificate-test
spec:
domains:
- test.host.com
最后,我创建了一个静态ip以便稍后在入口中分配它. 命令:"gcloud计算地址创建ip-test --global"
Finally, I have created a static ip to assign it later in the ingress. Command: "gcloud compute addresses create ip-test --global"
ingress.yaml:
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: basic-ingress
annotations:
kubernetes.io/ingress.global-static-ip-name: ip-test
networking.gke.io/managed-certificates: certificate-test
spec:
rules:
- host: test.host.com
http:
paths:
- backend:
serviceName: web
servicePort: 8080
就是这样.该服务适用于网址为"http://test.host.com"的网址,和"https://test.host.com",但是我想要的是当我进入端口80(即"http://test.host.com")时,系统会自动将我重定向到443(使用https).
That's it. The service works for the url "http://test.host.com" and "https://test.host.com", but what I want is that when I go to port 80 (that is to "http: //test.host.com ") automatically redirects me to 443 (with https).
我尝试将以下配置放入入口:"ingress.kubernetes.io/force-ssl-redirect:"真正的",但仍然无法正常工作.
I have tried to put the following configuration in the ingress: 'ingress.kubernetes.io/force-ssl-redirect:" true "', but it still doesn't work.
我希望比我了解更多的人能帮助我. 在此先向社区表示感谢,
I hope someone who understands something more than me can help me please. Thanks in advance to the community, greetings.
推荐答案
不幸的是,尽管GKE Ingress实现尚在实现中,但尚不支持HTTP到HTTPS重定向.参见 ingress-gce#1075 .
Unfortunately GKE Ingress implementation does not support HTTP to HTTPS redirection yet, although the feature is being implemented and should be available soon. See ingress-gce #1075.
目前,您有以下选择:
- 使用 ingress-nginx 代替GKE本机Ingress.
- /li>
- 自行实现重定向.在此处查看示例.
- replacing GKE native Ingress with the ingress-nginx
- implementing redirection yourself. See an example here.
这篇关于Kubernetes入口将http重定向到https的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!