Reputation: 333
Question
I wanted to inquire about the lifecycle of an object of type endpoints and would like to know if it is normal that the endpoints disappears automatically after a scale down of the Pod, to 0 instances?
Structure of the scenario
Kubernetes cluster v1.19 [1 master + 3 worker nodes]
Glusterfs endpoint (bound to the namespace) [includes the configuration IP addresses of the glusterfs devices]
Service [normal service for the pod and storage]
Deployment [includes relevant deployment informations e.g. env variables]
Structure of the interconnection pipeline
Endpoint -> Service -> Deployment
Endpoints yaml
apiVersion: v1
kind: Endpoints
metadata:
name: gluster-test
namespace: "test"
subsets:
- addresses:
- ip: "ip 1"
ports:
- port: 1
protocol: TCP
- addresses:
- ip: "ip 2"
ports:
- port: 1
protocol: TCP
- addresses:
- ip: "ip 3"
ports:
- port: 1
protocol: TCP
- addresses:
- ip: "ip 4"
ports:
- port: 1
protocol: TCP
Glusterfs service yaml
apiVersion: v1
kind: Service
metadata:
name: "gluster-test-sv"
namespace: "test"
spec:
ports:
- port: 1
Persistence volume yaml
apiVersion: v1
kind: PersistentVolume
metadata:
name: "gluster-test2-pv"
namespace: test
spec:
capacity:
storage: "5Gi"
accessModes:
- ReadWriteMany
glusterfs:
endpoints: gluster-test
path: "/test2"
readOnly: false
persistentVolumeReclaimPolicy: Retain
Persistence volume claim
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: "gluster-test2-claim"
namespace: test
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: "5Gi"
Deployment yaml
kind: Deployment
apiVersion: apps/v1
metadata:
name: "test-de"
labels:
app.kubernetes.io/name: "test"
namespace: kubernetes-dashboard
spec:
replicas: 1
selector:
matchLabels:
app.kubernetes.io/name: "test"
template:
metadata:
labels:
app.kubernetes.io/name: "test"
spec:
containers:
- name: "test"
image: "test:latest"
ports:
- name: http
containerPort: XXXX
protocol: TCP
volumeMounts:
- mountPath: /XXX
name: storage
readOnly: false
imagePullSecrets:
- name: "test"
volumes:
- name: storage
persistentVolumeClaim:
claimName: "gluster-test-claim"
securityContext:
fsGroup: XXX
Upvotes: 0
Views: 259
Reputation: 6853
Endpoint
is an object-oriented representation of REST API endpoint that is populated on the K8s APi server. Meaning that in K8s world it is the list of the addresses (IP and port) of the endpoints that implement a Service.
They are automatically created when a Service is created and configured with the pods matching the selector of the Service. Is is possible of course to create a service without selector. In this case you would have to create endpoints manually:
apiVersion: v1
kind: Endpoints
metadata:
name: glusterfs-cluster <--remember to match this with service name
subsets:
- addresses:
- ip: 10.10.10.10
ports:
- port:
- addresses:
- ip: 12.12.12.12
ports:
- port:
Note: In your examples endpoints name does not match the service name.
What is exactly happening behind the scenes is that kube-proxy watches the Kubernetes control plane for the addition and removal of Service and Endpoint objects. Then for each service it installs iptables rules which capture traffic to the Service's clusterIP
and port
and redirect that traffic to one of the Service's backed sets. For each Endpoint object, it installs iptables rules which select a backed Pod.
Upvotes: 1