简体   繁体   English

k8s中如何将IP地址分配给nginx Ingress资源?

[英]How to assign IP address to nginx Ingress resource in k8s?

I want to install nginx-controller in my Kube.netes cluster.我想在我的 Kube.netes 集群中安装 nginx-controller。 I setup my master node at one server, and worker node at another server.我在一台服务器上设置主节点,在另一台服务器上设置工作节点。 I am using Ubuntu 20.04.我正在使用 Ubuntu 20.04。

I followed the link ( https://github.com/kube.netes/ingress-nginx/blob/main/deploy/static/provider/cloud/1.23/deploy.yaml ) and use 'kubectl apply -f file_name.yaml' to install the controller.我点击了链接( https://github.com/kube.netes/ingress-nginx/blob/main/deploy/static/provider/cloud/1.23/deploy.yaml )并使用'kubectl apply -f file_name.yaml'安装 controller。

The controller pod is running: controller pod 正在运行:

NAME                                       READY   STATUS    RESTARTS   AGE
ingress-nginx-controller-c57bb9674-p2z9d   1/1     Running   0          70s

Now I want to create an Ingress resource.现在我想创建一个 Ingress 资源。 I used this yaml file:我使用了这个 yaml 文件:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ingress-hello
  namespace: ingress-nginx
  annotations:
    kubernetes.io/ingress.class: nginx
spec:
  rules:
    - http:
        paths:
        - path: /hello
          pathType: Exact
          backend:
            service:
              name: ingress-hello
              port:
                number: 80

However, when I applied this yaml file, and use ' kubectl get ingress -n ingress-nginx ', I saw:但是,当我应用这个 yaml 文件并使用“ kubectl get ingress -n ingress-nginx ”时,我看到:

NAME            CLASS    HOSTS   ADDRESS   PORTS   AGE
ingress-hello   <none>   *                 80      24s

I noticed that the address for this Ingress resource is empty.我注意到这个 Ingress 资源的地址是空的。

I am just wondering is it possible to assign an IP address to it?我只是想知道是否可以为它分配一个 IP 地址? Any method/ setting to assign the address?分配地址的任何方法/设置?

Thanks.谢谢。

You can access to your service by http://localhost:80/hello , and if you wanan specify a custom host you need to modify your ingnx file.您可以通过http://localhost:80/hello访问您的服务,如果您要指定自定义主机,则需要修改您的 ingnx 文件。

This is an example:这是一个例子:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ingress-hello
  namespace: ingress-nginx
  annotations:
    kubernetes.io/ingress.class: nginx
spec:
  rules:
    - host: your_host  
      http:
        paths:
        - path: /hello
          pathType: Exact
          backend:
            service:
              name: ingress-hello
              port:
                number: 80

and you need to open your hosts files in your /system32/etc/hosts directory and add your customized host , and then your service will be accessible through http://your_host:80/hello并且您需要打开/system32/etc/hosts目录中的主机文件并添加您的自定义host ,然后您的服务将可以通过http://your_host:80/hello访问

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

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