K8资源之endpoint资源&EP资源

1 endpoint资源概述

  • endpoint资源在K8S中用来表s示vc与后端 Pod 之间的连接关系的对象。当创建svc时,svc根据标签是否相同或svc名字是否和ep名字相同,把svc和ip关联上。

  • 删除svc时,会自动的删除同名的ep资源。

2 ep资源和svc的关联测试

yaml 复制代码
[root@master23107-ep]# cat 01-pod-svc.yaml 
apiVersion: v1
kind: Endpoints
metadata:
  name: wzy-web
subsets:
- addresses:
  - ip: 47.120.55.69
  # 如果一个ip地址下有多个port,需要指定名称
  ports:
  - port: 80
    name: http
  - port: 443
    name: https
---

apiVersion: v1
kind: Service
metadata:
  name: wzy-web
spec:
  type: ClusterIP
  ports:
  - port: 80
    # 由于ep使用了名称,所以这里必须指定一样的名称,否则无法关联
    name: http
  - port: 443
    name: https
bash 复制代码
[root@master23107-ep]# kubectl get ep,svc
NAME                   ENDPOINTS                          AGE
endpoints/kubernetes   10.0.0.231:6443                    7d7h
endpoints/wzy-web      47.120.55.69:80,47.120.55.69:443   8m13s

NAME                 TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE
service/kubernetes   ClusterIP   10.200.0.1       <none>        443/TCP          7d7h
service/wzy-web      ClusterIP   10.200.254.222   <none>        80/TCP,443/TCP   5m34s

2.访问测试。我的公网服务器设置了80会临时跳转到443

bash 复制代码
[root@master23107-ep]# curl 10.200.254.222:80
<html>
<head><title>302 Found</title></head>
<body>
<center><h1>302 Found</h1></center>
<hr><center>nginx/1.24.0</center>
</body>
</html>

[root@master23107-ep]# curl -k https://10.200.254.222:443
<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
	<meta http-equiv="Cache-Control" content="no-transform" />

3.删除svc wzy-web测试,发现ep wzy-web真的不见了

bash 复制代码
[root@master23107-ep]# kubectl get ep,svc
NAME                   ENDPOINTS                          AGE
endpoints/kubernetes   10.0.0.231:6443                    7d7h
endpoints/wzy-web      47.120.55.69:80,47.120.55.69:443   23s

NAME                 TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)          AGE
service/kubernetes   ClusterIP   10.200.0.1      <none>        443/TCP          7d7h
service/wzy-web      ClusterIP   10.200.92.170   <none>        80/TCP,443/TCP   23s
[root@master23107-ep]# kubectl delete svc wzy-web
service "wzy-web" deleted
[root@master23107-ep]# kubectl get ep
error: resource(s) were provided, but no name was specified
相关推荐
行止62 小时前
OpenStack云平台管理
linux·openstack
岁岁岁平安3 小时前
CentOS-7-x86_64解决:使用NAT模式无法ping通www.baidu.com或无法ping 8.8.8.8问题。
linux·运维·centos·centos-7
运维小贺3 小时前
各服务器厂商调整BIOS睿频教程
linux·运维·服务器·性能优化
Fanmeang3 小时前
OSPF路由过滤
运维·网络·华为·ip·路由·ospf·路由过滤
特种加菲猫3 小时前
指尖上的魔法:优雅高效的Linux命令手册
linux·笔记
★Orange★4 小时前
Linux Kernel kfifo 实现和巧妙设计
linux·运维·算法
我是阿呆同学4 小时前
仿mudou库one thread oneloop式并发服务器
网络
bemyrunningdog4 小时前
Mock数据
linux·运维·ubuntu
霖檬ing4 小时前
Ingress——2
k8s
是阿建吖!4 小时前
【Linux | 网络】网络编程套接字
linux·网络