简体   繁体   English

如何为 kube.netes 设置入口 controller?

[英]How to setup an ingress controller for kubernetes?

Sorry I am new with Kube.netes and everything... I have a java back-end in a clusterIP service and a front-end in a NodePort service.抱歉,我是 Kube.netes 和其他一切的新手……我在 clusterIP 服务中有一个 java 后端,在 NodePort 服务中有一个前端。 I try to make a request to the backend from the front (from the navigator) and it doesn't work.我尝试从前端(从导航器)向后端发出请求,但它不起作用。

I saw that I needed to setup an ingress crontroller in order to make it work, but each time I do a "minikube tunnel" and go to my localhost, I get a NGINX 404 error.我看到我需要设置一个入口控制程序才能使其工作,但每次我执行“minikube 隧道”和 go 到我的本地主机时,我都会收到 NGINX 404 错误。 And the address http://toto.virtualisation doesn't work too (like it doesn't exist).地址http://toto.virtualisation也不起作用(就像它不存在一样)。

Here is the setup of my front and my ingress controller in my yaml file:这是我的前端和入口 controller 在我的 yaml 文件中的设置:

# Front Deployment 
apiVersion: apps/v1
kind: Deployment
metadata:
  name: front-end-deployment
spec:
  selector:
    matchLabels:
      app: front-end
  template:
    metadata:
      labels:
        app: front-end
    spec:
        containers:
        - name: front-end-container
          image: oxasa/front-end-image:latest
---
# Front Service
apiVersion: v1
kind: Service
metadata:
  name: front-end-service
spec:
  ports:
    - name: http
      targetPort: 80
      port: 80
  type: NodePort
  selector:
    app: front-end
--- 
# Front Ingress
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: front-end-ingress
spec:
  rules:
  - host: toto.virtualisation
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: front-end-service
            port:
              number: 80

If you see anything that needs to be done to make it work...如果您看到任何需要做的事情才能让它发挥作用...

Try adding尝试添加

spec:
  ingressClassName: nginx

To the Ingress resource to ensure nginx picks up the created ingress.到 Ingress 资源以确保 nginx 获取创建的入口。

Also Ingress is not required for service to service Communication.服务到服务的通信也不需要 Ingress。 You can use the Kube.netes internal DNS from your Frontend service.您可以使用前端服务中的 Kube.netes 内部 DNS。 You can make the Frontend access backend by using sth like {service-name}.{namespace}.svc.cluster.local您可以使用 {service-name}.{namespace}.svc.cluster.local 之类的东西来创建前端访问后端

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM