nginx 无法访问使用AKS公开的特定neo4j数据库

niwlg2el  于 12个月前  发布在  Nginx
关注(0)|答案(1)|浏览(147)

我有一个aks集群,里面有两个neo4j数据库镜像(db-1和db-2),为这些提供服务。使用nginx ingress控制器,我想根据用户请求的URL将用户路由到特定的数据库,例如,如果用户想转到db-1,我的neo4j URL将是http://<external-ip>/db1
我想使用一个内部IP,并将我的aks集群链接到它。
我已经使用以下步骤创建了数据库和nginx控制器。但是我的数据库没有连接。Neo4j说Service Unavailable
helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
helm repo update
helm install ingress-nginx ingress-nginx/ingress-nginx --create-namespace --namespace ingress-test --set controller.service.annotations."service\.beta\.kubernetes\.io/azure-load-balancer-health-probe-request-path"=/healthz --set-string controller.service.annotations."service\.beta\.kubernetes\.io/azure-load-balancer-internal"="true" --tcp-services-configmap=ingress-test/tcp-services
应用下面的yaml kubectl apply -f ingress.yaml

kind: Deployment
metadata:
  name: aks-neo4j-one  
spec:
  replicas: 1
  selector:
    matchLabels:
      app: aks-neo4j-one
  template:
    metadata:
      labels:
        app: aks-neo4j-one
    spec:
      containers:  
      - name: neo4j  
        image: neo4j:latest 
        env:      
           - name: NEO4J_AUTH       
             value: neo4j/<mypassword>      
        ports:  
        - containerPort: 7474  
          name: http
        - containerPort: 7687  
          name: tcp
        
---
apiVersion: v1
kind: Service
metadata:
  name: aks-neo4j-one  
spec:
  type: ClusterIP
  ports:  
    - protocol: TCP  
      port: 80  
      targetPort: 7687 
  selector:
    app: aks-neo4j-one
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: neo4j-ingress  
spec:
  ingressClassName: nginx
  rules:
  - http:
      paths:
      - path: /neo4jone
        pathType: Prefix
        backend:
          service:
            name: aks-neo4j-one
            port:
              number: 80
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: tcp-services
  namespace: ingress-test
data:
  7687: "ingress-test/aks-neo4j-one:80"
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: ingress-nginx-controller
  namespace: ingress-test
spec:
  template:
    spec:
      containers:
      - name: controller
        args:
          - /nginx-ingress-controller
          - --tcp-services-configmap=ingress-test/tcp-services

字符串
有没有尝试过它与配置Map以及neo4j需要7687螺栓端口
将服务端口更改为7474,并浏览外部IP会弹出用户名和密码,并且不会继续进行任何输入。

kpbwa7wx

kpbwa7wx1#

要在AKS集群中配置两个独立的Neo4j示例,并使用Nginx Ingress基于URL路径将流量定向到它们,请按照以下说明操作:

第一步:安装Nginx Ingress Controller

首先,添加Nginx Ingress的Helm仓库并安装:

helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
helm repo update
helm install ingress-nginx ingress-nginx/ingress-nginx --create-namespace --namespace ingress-nginx

字符串


的数据

第二步:部署Neo4j集群

为每个Neo4j示例创建Kubernetes部署文件。对于第一个数据库(db-1):

#File: db1-deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: neo4j-db1
spec:
  replicas: 1
  selector:
    matchLabels:
      app: neo4j-db1
  template:
    metadata:
      labels:
        app: neo4j-db1
    spec:
      containers:
        - name: neo4j
          image: neo4j:latest
          env:
            - name: NEO4J_AUTH
              value: "neo4j/your_password_here"
          ports:
            - containerPort: 7474
              name: http
            - containerPort: 7687
              name: bolt


对于第二个数据库(db-2):

#File: db2-deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: neo4j-db2
spec:
  replicas: 1
  selector:
    matchLabels:
      app: neo4j-db2
  template:
    metadata:
      labels:
        app: neo4j-db2
    spec:
      containers:
        - name: neo4j
          image: neo4j:latest
          env:
            - name: NEO4J_AUTH
              value: "neo4j/your_password_here"
          ports:
            - containerPort: 7474
              name: http
            - containerPort: 7687
              name: bolt


使用以下命令部署这些配置:

kubectl apply -f db1-deployment.yaml 
kubectl apply -f db2-deployment.yaml


第三步:公开Neo4j服务

现在,为每个Neo4j部署定义服务。对于db-1

# db1-service.yaml
apiVersion: v1
kind: Service
metadata:
  name: neo4j-db1-service
spec:
  type: ClusterIP
  ports:
    - name: http
      protocol: TCP
      port: 7474
      targetPort: 7474
    - name: bolt
      protocol: TCP
      port: 7687
      targetPort: 7687
  selector:
    app: neo4j-db1


对于db-2

# db2-service.yaml
apiVersion: v1
kind: Service
metadata:
  name: neo4j-db2-service
spec:
  type: ClusterIP
  ports:
    - name: http
      protocol: TCP
      port: 7474
      targetPort: 7474
    - name: bolt
      protocol: TCP
      port: 7687
      targetPort: 7687
  selector:
    app: neo4j-db1


应用它们:

kubectl apply -f db1-service.yaml
kubectl apply -f db2-service.yaml


第四步:配置Ingress路由

设置一个Ingress资源来路由外部请求:

# File: neo4j-ingress.yaml

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: neo4j-ingress
spec:
  ingressClassName: nginx
  rules:
    - http:
        paths:
          - path: /db1
            pathType: Prefix
            backend:
              service:
                name: neo4j-db1-service
                port:
                  number: 7474
          - path: /db2
            pathType: Prefix
            backend:
              service:
                name: neo4j-db2-service
                port:
                  number: 7474


使用kubectl apply -f neo4j-ingress.yaml应用它



应用上述配置后,为TCP路由创建一个ConfigMap:

apiVersion: v1
kind: ConfigMap
metadata:
  name: nginx-ingress-tcp
  namespace: ingress-nginx
data:
  "7687": "default/neo4j-db1-service:7687"


应用配置Map:kubectl apply -f tcp-routing-configmap.yaml

然后,更新Nginx Ingress Controller部署以使用TCP服务的ConfigMap:kubectl edit deployment ingress-nginx-controller -n ingress-nginx
spec.template.spec.containers[0].args下添加--tcp-services-configmap=default/nginx-ingress-tcp参数。



应用上述配置后,您应该可以在http://<external-ip>/db1(HTTP)和<external-ip>:7687(Bolt)访问您的Neo4j示例。通过以下方式查找Nginx ingress控制器的外部IP:

kubectl get svc -n ingress-nginx


相关问题