|NO.Z.00166|——————————|CloudNative|——|KuberNetes&服务发布.V17|——|ingress.v05|创建多级域名ingress.pod|

一、创建一个多域名ingress
### --- 创建多域名ingress.yaml配置文件

[root@k8s-master01 ~]# vim ingress-mulDomain.yaml
apiVersion: networking.k8s.io/v1beta1 # networking.k8s.io/v1 / extensions/v1beta1 
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.class: "nginx"
  name: example
spec:
  rules:                            # 一个Ingress可以配置多个rules
  - host: foo.bar.com               # 域名配置,可以不写,匹配*, *.bar.com
    http:
      paths:                        # 相当于nginx的location配合,同一个host可以配置多个path / /abc
      - backend:
          serviceName: nginx-svc 
          servicePort: 80
        path: /
  - host: foo2.bar.com              # 域名配置,可以不写,匹配*, *.bar.com
    http:
      paths:                        # 相当于nginx的location配合,同一个host可以配置多个path / /abc
      - backend:
          serviceName: nginx-svc-external
          servicePort: 80
        path: /
二、创建多域名的ingress
### --- 创建多域名ingress
~~~     因为我们Ingress已经存在,我们重新更新一下

[root@k8s-master01 ~]# kubectl replace -f ingress-mulDomain.yaml        
Warning: networking.k8s.io/v1beta1 Ingress is deprecated in v1.19+, unavailable in v1.22+; use networking.k8s.io/v1 Ingress
ingress.networking.k8s.io/example replaced
### --- 查看创建的ingress

[root@k8s-master01 ~]# kubectl get ingress
NAME      CLASS    HOSTS                      ADDRESS        PORTS   AGE
example   <none>   foo.bar.com,foo2.bar.com   10.107.59.89   80      19m 
三、查看创建的ingress.yaml配置文件
### --- 查看创建的ingress配置文件

[root@k8s-master01 ~]# kubectl get ingress -oyaml 
  spec:
    rules:
    - host: foo.bar.com
      http:
        paths:
        - backend:
            service:
              name: nginx-svc
              port:
                number: 80
          path: /
          pathType: ImplementationSpecific
    - host: foo2.bar.com
      http:
        paths:
        - backend:
            service:
              name: nginx-svc-external
              port:
                number: 80
          path: / 
          pathType: ImplementationSpecific
### --- 配置hosts文件,并通过Chrome访问这两个域名: foo.bar.com和 foo2.bar.com

~~~     可以正常访问到welcome tonginx,
~~~     若是foo2.bar.com返回值为501 Not Implemented,说明是可以访问的,
~~~     但是可能不能跨域访问。是能说明我们的多域名配置 是没有问题的。
### --- 在写域名的时候,涉及到 rearunte的时候;

~~~     # 需要做rearunte的域名和不需要做rearunte的域名需要分开写,写成两个Ingress
~~~     因为有的域名是不需要Rearunte的,若是写在一块,
~~~     有可能两个域名都Rearunte掉。会造成问题。
~~~     # 创建建议:
~~~     同一类型的写在一块,要么是都需要Rearunte要么是都不需要Rearunte,
~~~     若是配置都一样的话可以写在一块。

 
 
 
 
 
 
 
 
 

Walter Savage Landor:strove with none,for none was worth my strife.Nature I loved and, next to Nature, Art:I warm'd both hands before the fire of life.It sinks, and I am ready to depart
                                                                                                                                                   ——W.S.Landor

 

 

posted on   yanqi_vip  阅读(42)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· DeepSeek 开源周回顾「GitHub 热点速览」
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

导航

统计

点击右上角即可分享
微信分享提示