问题描述
如果我注册了域名www.domain.com
,并且我有新的kubernetes集群启动并正在运行.我已经成功启动了Deployments
和Services
来公开要求.
If I have a domain name www.domain.com
registered and I have fresh kubernetes cluster up and running. I have successfully lauched Deployments
and Services
to expose the requirements.
该服务正在我的GCE群集上创建LoadBalancer
,并且当我尝试通过外部IP访问APP
时,其工作正常.
The service is creating a LoadBalancer
on my GCE cluster and when I try to access my APP
through the the external IP its working.
但这是我理想中想要实现的目标:
But this is what I wanted to achieve ideally :
要将我的应用程序的所有流量路由为www.app.domain.com
,www.app2.domain.com
.经过研究,我发现我需要一个Ingress Controller
最好是NGINX
服务器,但我一直在尝试这样做,但失败了.
To route all the traffic for my apps as www.app.domain.com
, www.app2.domain.com
. Upon research I have found that I need an Ingress Controller
preferably NGINX
server, I have been try to do this and failing miserably.
这是为我的部署公开JSON的服务:
This is the service exposing JSON for my deployments:
{
"kind": "Service",
"apiVersion": "v1",
"metadata": {
"name": 'node-js-srv'
},
"spec": {
"type": 'LoadBalancer',
"label": {
'app': 'node-js-srv'
},
"ports": [
{
"targetPort": 8080,
"protocol": "TCP",
"port": 80,
"name": "http"
},
{
"protocol": "TCP",
"port": 443,
"name": "https",
"targetPort": 8080
}
],
"selector": {
"app": 'node-js'
},
}
}
推荐答案
GCE/GKE已经有一个Ingress Controller
,您可以使用它.
GCE/GKE have already a Ingress Controller
and you could use that one.
您必须将服务指定为NodePort
类型,并从Ingress
类型创建资源看: https://kubernetes.io/docs/user-guide/ingress/
You must specify your service as type NodePort
and create a ressource from type Ingress
See:https://kubernetes.io/docs/user-guide/ingress/
您可以在 https://github上找到GCE的示例. com/kubernetes/ingress/tree/master/examples/deployment/gce
服务:
{
"kind": "Service",
"apiVersion": "v1",
"metadata": {
"name": 'node-js-srv'
},
"spec": {
"type": 'NodePort',
"label": {
'app': 'node-js-srv'
},
"ports": [
{
"targetPort": 8080,
"protocol": "TCP",
"port": 80,
"name": "http"
},
{
"protocol": "TCP",
"port": 443,
"name": "https",
"targetPort": 8080
}
],
"selector": {
"app": 'node-js'
},
}
}
入口:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: test
spec:
rules:
- host: www.app.domain.com
http:
paths:
- backend:
serviceName: node-js-srv
servicePort: 80
- host: www.app2.domain.com
http:
paths:
- backend:
serviceName: xyz
servicePort: 80
这篇关于Kubernetes集群APP DNS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!