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

④. Ingress的域名访问


  • ①. 在master主节点进行如下的命令操作


[root@k8smaster ~]# kubectl apply -f ingress-rule.yaml 
ingress.networking.k8s.io/ingress-host-bar created
[root@k8smaster ~]# kubectl get ingress
NAME               CLASS   HOSTS                                ADDRESS   PORTS   AGE
ingress-host-bar   nginx   hello.xiaozhi.com,demo.xiaozhi.com             80      5s
[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                     8m35s
default                kubernetes                           ClusterIP   10.96.0.1       <none>        443/TCP                      12d
default                my-dep-01                            NodePort    10.96.235.249   <none>        8000:30267/TCP               44m
default                nginx-demo                           ClusterIP   10.96.221.252   <none>        8000/TCP                     8m35s
ingress-nginx          ingress-nginx-controller             NodePort    10.96.183.241   <none>        80:32128/TCP,443:31148/TCP   26m
ingress-nginx          ingress-nginx-controller-admission   ClusterIP   10.96.31.69     <none>        443/TCP                      26m
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:
  name: ingress-host-bar
spec:
  ingressClassName: nginx
  rules:
  - host: "hello.xiaozhi.com"
    http:
      paths:
      - pathType: Prefix
        path: "/"
        backend:
          service:
            name: hello-server
            port:
              number: 8000
  - host: "demo.xiaozhi.com"
    http:
      paths:
      - pathType: Prefix
        path: "/"  # 把请求会转给下面的服务,下面的服务一定要能处理这个路径,不能处理就是404
        backend:
          service:
            name: nginx-demo  ## java,比如使用路径重写,去掉前缀nginx
            port:
              number: 8000


②. 配置本地的hosts


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


③. 页面访问


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


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


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



上一篇:小企业一般需要哪种类型的服务器和操作系统


下一篇:Kubernetes集群安装部署