KUBERNETES04_Service服务ClusterIP、NodePort方式、Ingress域名访问、路径重写、限流操作(五)

⑤. Ingress的路径重写


  • ①. 使用命令重新启动ingress


[root@k8smaster ~]# kubectl apply -f ingress-rule.yaml
[root@k8smaster ~]# kubectl get ing
NAME               CLASS   HOSTS                                ADDRESS          PORTS   AGE
ingress-host-bar   nginx   hello.xiaozhi.com,demo.xiaozhi.com   192.168.68.145   80      12m
[root@k8smaster ~]# kubectl get service -A
NAMESPACE              NAME                                 TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)                      AGE
default                hello-server                         ClusterIP   10.96.179.231   <none>        8000/TCP                     142m
default                kubernetes                           ClusterIP   10.96.0.1       <none>        443/TCP                      12d
default                my-dep-01                            NodePort    10.96.235.249   <none>        8000:30267/TCP               178m
default                nginx-demo                           ClusterIP   10.96.221.252   <none>        8000/TCP                     142m
ingress-nginx          ingress-nginx-controller             NodePort    10.96.183.241   <none>        80:32128/TCP,443:31148/TCP   160m
ingress-nginx          ingress-nginx-controller-admission   ClusterIP   10.96.31.69     <none>        443/TCP                      160m
kube-system            kube-dns                             ClusterIP   10.96.0.10      <none>        53/UDP,53/TCP,9153/TCP       12d
kubernetes-dashboard   dashboard-metrics-scraper            ClusterIP   10.96.219.52    <none>        8000/TCP                     12d
kubernetes-dashboard   kubernetes-dashboard                 NodePort    10.96.235.195   <none>        443:32476/TCP                12d
[root@k8smaster ~]#


apiVersion: networking.k8s.io/v1
kind: Ingress  
metadata:
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$2
  name: ingress-host-bar
spec:
  ingressClassName: nginx
  rules:
  - host: "hello.atguigu.com"
    http:
      paths:
      - pathType: Prefix
        path: "/"
        backend:
          service:
            name: hello-server
            port:
              number: 8000
  - host: "demo.atguigu.com"
    http:
      paths:
      - pathType: Prefix
        path: "/nginx(/|$)(.*)"  # 把请求会转给下面的服务,下面的服务一定要能处理这个路径,不能处理就是404
        backend:
          service:
            name: nginx-demo  ## java,比如使用路径重写,去掉前缀nginx
            port:
              number: 8000


KUBERNETES04_Service服务ClusterIP、NodePort方式、Ingress域名访问、路径重写、限流操作(五)


KUBERNETES04_Service服务ClusterIP、NodePort方式、Ingress域名访问、路径重写、限流操作(五)



上一篇:WCF流量控制


下一篇:CentOS下*面静默安装oracle 11g