【K8s Endpoint(端点)】

文章介绍了Kubernetes中Endpoint的概念,作为服务注册的一种方式,它记录Service对应的Pod地址。通过创建Deployment来部署Pod,然后使用Service配合Selector将请求路由到正确的Pod。Service类型为ClusterIP,实现了内部的负载均衡。通过kubectl命令展示了创建和查询Endpoint及Service的过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值