<p><strong>Question</strong></p>
<p>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?</p>
<p><strong>Structure of the scenario</strong></p>
<p>Kubernetes cluster v1.19 [1 master + 3 worker nodes]</p>
<p>Glusterfs endpoint (bound to the namespace) [includes the configuration IP addresses of the glusterfs devices]</p>
<p>Service [normal service for the pod and storage]</p>
<p>Deployment [includes relevant deployment informations e.g. env variables]</p>
<p><strong>Structure of the interconnection pipeline</strong></p>
<p>Endpoint -&gt; Service -&gt; Deployment</p>
<p><strong>Endpoints yaml</strong></p>
<pre><code>apiVersion: v1
kind: Endpoints
metadata:
name: gluster-test
namespace: &quot;test&quot;
subsets:
- addresses:
    - ip: &quot;ip 1&quot;
  ports:
    - port: 1
      protocol: TCP
- addresses:
    - ip: &quot;ip 2&quot;
  ports:
    - port: 1
      protocol: TCP
- addresses:
    - ip: &quot;ip 3&quot;
  ports:
    - port: 1
      protocol: TCP
- addresses:
    - ip: &quot;ip 4&quot;
  ports:
    - port: 1
      protocol: TCP
</code></pre>
<p><strong>Glusterfs service yaml</strong></p>
<pre><code>apiVersion: v1
kind: Service
metadata:
name: &quot;gluster-test-sv&quot;
namespace: &quot;test&quot;
spec:
ports:
  - port: 1
</code></pre>
<p><strong>Persistence volume yaml</strong></p>
<pre><code>apiVersion: v1
kind: PersistentVolume
metadata:
name: &quot;gluster-test2-pv&quot;
namespace: test
spec:
capacity:
  storage: &quot;5Gi&quot;
accessModes:
  - ReadWriteMany
glusterfs:
  endpoints: gluster-test
  path: &quot;/test2&quot;
  readOnly: false
persistentVolumeReclaimPolicy: Retain
</code></pre>
<p><strong>Persistence volume claim</strong></p>
<pre><code>apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: &quot;gluster-test2-claim&quot;
namespace: test
spec:
accessModes:
  - ReadWriteMany
resources:
  requests:
    storage: &quot;5Gi&quot;
</code></pre>
<p><strong>Deployment yaml</strong></p>
<pre><code>kind: Deployment
apiVersion: apps/v1
metadata:
name: &quot;test-de&quot;
labels:
  app.kubernetes.io/name: &quot;test&quot;
namespace: kubernetes-dashboard
spec:
replicas: 1
selector:
  matchLabels:
    app.kubernetes.io/name: &quot;test&quot;
template:
  metadata:
    labels:
      app.kubernetes.io/name: &quot;test&quot;
  spec:
    containers:
      - name: &quot;test&quot;
        image: &quot;test:latest&quot;
        ports:
          - name: http
            containerPort: XXXX
            protocol: TCP
        volumeMounts:
          - mountPath: /XXX
            name: storage
            readOnly: false
    imagePullSecrets:
      - name: &quot;test&quot;
    volumes:
      - name: storage
        persistentVolumeClaim:
          claimName: &quot;gluster-test-claim&quot;
    securityContext:
      fsGroup: XXX
</code></pre>

ZPascal
<p><code>Endpoint</code> 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.</p>
<p>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:</p>
<pre><code>apiVersion: v1
kind: Endpoints
metadata:
  name: glusterfs-cluster &lt;--remember to match this with service name
subsets:
  - addresses:
      - ip: 10.10.10.10 
    ports:
      - port: 
  - addresses:
      - ip: 12.12.12.12 
    ports:
      - port: 
</code></pre>
<p><strong>Note: In your examples endpoints name does not match the service name.</strong></p>
<p>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 <code>clusterIP</code> and <code>port</code> 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.</p>
