Ingress和Ingress控制器如何将它们与NodePort Services一起使用? [英] Ingress and Ingress controller how to use them with NodePort Services?

查看:898
本文介绍了Ingress和Ingress控制器如何将它们与NodePort Services一起使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在NodePort服务上运行了一个服务.如何使用入口访问多个服务.

I have a single service running on a NodePort service. How do i use ingress to access multiple services.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: auth
spec:
  replicas: 1
  selector:
    matchLabels:
      app: auth
  template:
    metadata:
      labels:
        app: auth
        tier: backend
        track: dev
    spec:
      containers:
        - name: auth
          image: [url]/auth_app:v2
          ports:
            - name: auth
              containerPort: 3000

service.yml

apiVersion: v1
kind: Service
metadata:
  name: auth
spec:
  selector:
    app: auth
    tier: backend
  ports:
    - protocol: TCP
      port: 3000
      targetPort: auth
  type: NodePort

ingress.yml

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: test-ingress
spec:
  backend:
    serviceName: auth
    servicePort: 8080

我从回购.我无法在我的端口配置中使用它. 我是一个初学者,想要一些资源.

I followed step by step from the this repo. I could not get it working for my port config. I'm a beginner and would like some resources for the same.

推荐答案

您的服务正在端口3000中运行,但是您的入口路由规则与端口8080匹配.如果仅将后端的servicePort更改为3000,则该规则可能会起作用Ingress资源定义部分.

Your service is running in port 3000 but your Ingress routing rule is matching to port 8080. It will probably work if you just change the servicePort to 3000 in the backend section of your Ingress resource definition.

我建议在尝试Ingress之前先确保它与NodePort兼容.我建议这样做是因为我注意到您的服务仅指定端口和targetPort的值,而不指定nodePort的值.如果未指定nodeport值,则将获得一个随机端口号.由于您想将Ingress与NodePort服务类型一起使用,因此随机端口号应该无关紧要.

I'd suggest making sure it works with NodePort first before trying Ingress. I suggest this because I notice your Service only specifies values for port and targetPort but not nodePort. If you do not specify a nodeport value, you will get a random port number. As you want to use ingress with NodePort service type, the random port number should not matter.

对于NodePort教程,您可以从 https://medium.com/@markgituma/kubernetes-local-to-production-with-django-2-docker-and-minikube-ba843d858817 ,因为我注意到您已标记了您的帖子与Django

For NodePort tutorials you could start with https://medium.com/@markgituma/kubernetes-local-to-production-with-django-2-docker-and-minikube-ba843d858817 as I notice you've tagged your post with django

对于nginx入口,您可以看到 https://cloud.google.com /community/tutorials/nginx-ingress-gke ,但是如果您不使用gke,则可能想找到特定于您云平台的内容

For nginx ingress you could see https://cloud.google.com/community/tutorials/nginx-ingress-gke but you might want to find something specific to your cloud platform if you're not using gke

最好是从一项服务开始,但是要了解它如何适用于多种服务,您可以在docs

It is best to start with one service but to understand how this can work for multiple services you could have a look at the fanout ingress example in the docs https://kubernetes.io/docs/concepts/services-networking/ingress/#simple-fanout

这篇关于Ingress和Ingress控制器如何将它们与NodePort Services一起使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆