|NO.Z.00418|——————————|CloudNative|——|KuberNetes&NetworkPolicy.V10|——|Ingress.v01|服务发布限制.v01|

一、服务发布限制于Ingress:架构图
二、架构图概述
### --- 架构图概述

~~~     一个项目前端和网关对外暴露,其它的应用是不需要对外暴露得
~~~     假设有一个SpringCloud项目,可能会有一个nodejs作为前端,zuul作为网关入口,
~~~     发布应用的时候,会在ingress-nginx上配置一个根到前端
~~~     再配置一个api到zuul,这个zuul就会实现内部的路由。
~~~     那么就需要这2个服务暴露对外即可,其它的微服务是不需要暴露在外的。
~~~     就需要把nodejs和zuul公布于ingress controller,只要ingress controller访问这2个微服务,
~~~     那么就在这个命名空间下配置网络策略,只需要ingress,controller前端访问nodejs和zuul
三、创建nginx服务
### --- 创建nginx服务

[root@k8s-master01 ~]#  kubectl  create deploy nginx --image=registry.cn-beijing.aliyuncs.com/dotbalo/nginx:latest -n nw-demo
deployment.apps/nginx created
### --- 暴露服务

[root@k8s-master01 ~]# kubectl expose deploy nginx -n nw-demo --port=80
service/nginx exposed 
四、查看创建的pod和service
### --- 查看创建的pod

[root@k8s-master01 ~]# kubectl get po -n nw-demo -owide
NAME                     READY   STATUS    RESTARTS   AGE     IP               NODE           NOMINATED NODE   READINESS GATES
nginx-67d8d8bffb-6zjzx   1/1     Running   0          4m51s   172.25.92.116    k8s-master02   <none>           <none>
### --- 查看创建的service

[root@k8s-master01 ~]# kubectl get svc -n nw-demo -owide
NAME    TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)   AGE   SELECTOR
nginx   ClusterIP   10.96.82.110   <none>        80/TCP    55s   app=nginx
### --- 查看创建的endpoints

[root@k8s-master01 ~]# kubectl get endpoints -n nw-demo -owide
NAME    ENDPOINTS          AGE
nginx   172.25.92.116:80   61s
五、验证测试
### --- 验证在没有做任何网络策略的情况下是否可以通信
~~~     在宿主机上访问nginx服务

[root@k8s-master01 ~]# curl 10.96.82.110
<h1>Welcome to nginx!</h1>
### --- 在不同namespace下通过pod验证是否可以通信
~~~     # 通过default命名空间下pod验证

[root@k8s-master01 ~]# kubectl get po -owide
NAME                          READY   STATUS    RESTARTS   AGE   IP               NODE           NOMINATED NODE   READINESS GATES
debug-tools                   1/1     Running   1          29m   172.25.244.242   k8s-master01   <none>           <none>
~~~     # 验证是否可以访问
~~~     跨namespace反问是可以通信的 

[root@k8s-master01 ~]# kubectl exec -ti debug-tools  -- bash
(14:30 debug-tools:/) curl http://nginx.nw-demo
<h1>Welcome to nginx!</h1>

 
 
 
 
 
 
 
 
 

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  阅读(31)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· DeepSeek 开源周回顾「GitHub 热点速览」
< 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

导航

统计

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