如果我注册了域名www.domain.com
,我就会拥有新的kubernetes群集并运行。我已成功推出Deployments
和Services
以公开要求。
该服务正在我的GCE群集上创建LoadBalancer
,当我尝试通过其工作的外部IP访问我的APP
时。
但这是我想要达到的理想目标:
要将我的应用的所有流量路由为www.app.domain.com
,www.app2.domain.com
。经过研究,我发现我需要一个Ingress Controller
最好NGINX
服务器,我一直试图做到这一点并且失败了。
这是为我的部署公开JSON的服务:
{
"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'
},
}
}
答案 0 :(得分:0)
GCE / GKE已经有Ingress Controller
,你可以使用那个。
您必须将服务指定为NodePort
类型,并从类型Ingress
创建一个资源
看到:
https://kubernetes.io/docs/user-guide/ingress/
您可以在此处找到GCE的示例https://github.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