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