【K8s Endpoint(端点)】
Endpoint是kubernetes中的一个资源对象,存储在etcd中,用于记录一个service对应的所有pod的访问地址。通俗易懂总结:kubernetes 中的 Service与Endpoints通讯获取实际服务地址,在路由转发到具体pod上。一个Service由一组Pod组成,这些Pod通过Endpoints暴露出来,Endpoints是实现实际服务的端点集合。1.启动我们的pod集群(
·
Endpoint(端点)
Endpoint 类似服务注册中心 (eureka、nacos、zookeeper)
Endpoint是kubernetes中的一个资源对象,存储在etcd中,用于记录一个service对应的所有pod的访问地址
一个Service由一组Pod组成,这些Pod通过Endpoints暴露出来,Endpoints是实现实际服务的端点集合。
通俗易懂总结:kubernetes 中的 Service与Endpoints通讯获取实际服务地址,在路由转发到具体pod上。
#szsh-deployment-service01.yml 创建pod的yml
apiVersion: apps/v1
kind: Deployment
metadata:
name: szsh-deployment
namespace: sz-sit
spec:
replicas: 3
selector:
matchLabels:
app: nginx-pod
template:
metadata:
labels:
app: nginx-pod
spec:
containers:
- name: nginx
image: nginx:1.17.9
ports:
- containerPort: 80
创建命名空间
kubectl create ns sz-sit
创建三个pod
kubectl create -f szsh-deployment-service01.yml
#szyh-clusterip-service02.yml 创建service的yml
apiVersion: v1
kind: Service
metadata:
name: szyh-clusterip
namespace: sz-sit
spec:
selector:
app: nginx-pod
clusterIP: # service的ip地址, 如果不写默认会生成一个随机的IP
type: ClusterIP
ports:
- port: 80 # Service端口
targetPort: 80 # pod端口
sessionAffinity: ClientIP
创建管理nginx-pod的szyh-clusterip service
kubectl create -f szyh-clusterip-service02.yml
kubectl describe svc szyh-clusterip -n sz-sit(namespace)
kubectl get endpoints -n sz-sit(namespace) -o wide
原理:
1.启动我们的pod集群(给每个pod打上标签nginx-pod);
2.创建我们service的时候 配置对应选择器selector标签 知道
service管理哪些pod集群;
更多推荐
已为社区贡献1条内容
所有评论(0)