Repository: kubernetes
Issue: A DaemonSet pod environment variable did not inject service information
Labels: kind/bug,sig/apps,lifecycle/rotten,needs-triage

### What happened?

I have a k8s cluster and created a DaemonSet in the cluster that is associated with three pods. I found that one of the pods did not inject service information into its environment variables

services:
```shell
[root@controller-0-2:/k8s]$ kubectl get svc -n admin
NAME                          TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)    AGE
assem-apiserver           ClusterIP   fd00::5be3   <none>        2509/TCP   23h
assem-apiserver-cluster   ClusterIP   fd00::e0b3   <none>        2509/TCP   23h
```
The problematic pod environment variable information is as follows:
```shell
[root@controller-0-2:/k8s]$ kubectl exec -it -n admin         assem-cic-kbbb8 -- env
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HOSTNAME=controller-0-2
ENV=/etc/profile
POD_NAMESPACE=admin
POD_NAME=assem-cic-kbbb8
KUBERNETES_PORT=tcp://[fd00::1]:443
KUBERNETES_PORT_443_TCP=tcp://[fd00::1]:443
KUBERNETES_PORT_443_TCP_PROTO=tcp
KUBERNETES_PORT_443_TCP_PORT=443
KUBERNETES_PORT_443_TCP_ADDR=fd00::1
KUBERNETES_SERVICE_HOST=fd00::1
KUBERNETES_SERVICE_PORT=443
KUBERNETES_SERVICE_PORT_HTTPS=443
TERM=xterm
```

The normal pod environment variables are as follows:
```shell
[root@controller-0-0:/k8s]$ kubectl exec -it -n admin         assem-cic-jbzbh -- env
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HOSTNAME=-controller-0-0
ENV=/etc/profile
POD_NAME=op-assem-cic-jbzbh 
POD_NAMESPACE=admin
ASSEM_APISERVER_CLUSTER_PORT_2509_TCP=tcp://[fd00::e0b3]:2509
ASSEM_APISERVER_PORT_2509_TCP_PORT=2509
KUBERNETES_SERVICE_HOST=fd00::1
ASSEMAPISERVER_CLUSTER_SERVICE_PORT_HTTPS=2509
ASSEM_APISERVER_CLUSTER_PORT=tcp://[fd00::e0b3]:2509
ASSEM_APISERVER_CLUSTER_PORT_2509_TCP_PROTO=tcp
ASSEM_APISERVER_CLUSTER_PORT_2509_TCP_PORT=2509
ASSEM_APISERVER_SERVICE_PORT_HTTPS=2509
ASSEM_APISERVER_PORT_2509_TCP_PROTO=tcp
ASSEM_APISERVER_PORT_2509_TCP_ADDR=fd00::5be3
ASSEM_APISERVER_CLUSTER_SERVICE_HOST=fd00::e0b3
KUBERNETES_PORT_443_TCP_PROTO=tcp
KUBERNETES_PORT_443_TCP_PORT=443
ASSEM_APISERVER_CLUSTER_SERVICE_PORT=2509
ASSEM_APISERVER_PORT=tcp://[fd00::5be3]:2509
ASSEM_APISERVER_CLUSTER_PORT_2509_TCP_ADDR=fd00::e0b3
ASSEM_APISERVER_SERVICE_PORT=2509
KUBERNETES_SERVICE_PORT_HTTPS=443
KUBERNETES_PORT_443_TCP=tcp://[fd00::1]:443
ASSEM_APISERVER_PDM_SERVICE_PORT=2509
ASSEM_APISERVER_SERVICE_HOST=fd00::5be3
ASSEM_APISERVER_PORT_2509_TCP=tcp://[fd00::5be3]:2509
KUBERNETES_SERVICE_PORT=443
KUBERNETES_PORT=tcp://[fd00::1]:443
KUBERNETES_PORT_443_TCP_ADDR=fd00::1
TERM=xterm
```

`assem-apiserver` service creation time:  
```shell
creationTimestamp: "2024-09-18T03:37:28Z"
```

`assem-apiserver-cluster` service creation time:  
```shell
creationTimestamp: "2024-09-18T03:37:28Z"
```

`assem-cic-kbbb8 ` pod creation time:
```yaml
[root@controller-0-2:/k8s]$ kubectl get po -n admin        assem-cic-kbbb8 -oyaml
apiVersion: v1
kind: Pod
metadata:
  creationTimestamp: "2024-09-18T03:37:28Z"
 ...
  namespace: admin
  ownerReferences:
  - apiVersion: apps/v1
    blockOwnerDeletion: true
    controller: true
    kind: DaemonSet
    name: assem-cic
    uid: 0c5601ca-d6ab-4db7-8d8b-e18321e3e741
  resourceVersion: "2092"
  uid: 4b96702a-c0ff-4a6e-9510-2ec0f467ceee
spec:
  ...
  dnsPolicy: ClusterFirstWithHostNet
  enableServiceLinks: true
  hostNetwork: true
 ...
status:
  conditions:
  - lastProbeTime: null
    lastTransitionTime: "2024-09-18T03:37:31Z"
    status: "True"
    type: Initialized
  - lastProbeTime: null
    lastTransitionTime: "2024-09-18T03:38:46Z"
    status: "True"
    type: Ready
  - lastProbeTime: null
    lastTransitionTime: "2024-09-18T03:38:46Z"
    status: "True"
    type: ContainersReady
  - lastProbeTime: null
    lastTransitionTime: "2024-09-18T03:37:28Z"
    status: "True"
    type: PodScheduled
  containerStatuses:
  - containerID: containerd://9529e9564e71706ada80b6280e16537418e35fe61aa5e013d4fbc90c29f113c5
    ...
    ready: true
    restartCount: 0
    started: true
    state:
      running:
        startedAt: "2024-09-18T03:37:32Z"
  hostIP: 193:116:66::19
  initContainerStatuses:
  - containerID: containerd://69507fe03ce358b168be50336dc6361b2aa1581ad0bae1bec4d3b3da62d7b90a
   ...
    restartCount: 0
    started: false
    state:
      terminated:
        containerID: containerd://69507fe03ce358b168be50336dc6361b2aa1581ad0bae1bec4d3b3da62d7b90a
        exitCode: 0
        finishedAt: "2024-09-18T03:37:30Z"
        reason: Completed
        startedAt: "2024-09-18T03:37:30Z"
  phase: Running
  podIP: 193:116:66::19
  podIPs:
  - ip: 193:116:66::19
  - ip: 192.0.0.40
  qosClass: Burstable
  startTime: "2024-09-18T03:37:28Z"

```  

` assem-cic-jbzbh ` pod creation time:
```yaml
[root@controller-0-2:/k8s]$ kubectl get po -n admin         assem-cic-jbzbh -oyaml
apiVersion: v1
kind: Pod
metadata:
  ...
  creationTimestamp: "2024-09-18T03:37:28Z"
  generateName: assem-cic-
  ...
  namespace: admin
  ownerReferences:
  - apiVersion: apps/v1
    blockOwnerDeletion: true
    controller: true
    kind: DaemonSet
    name: assem-cic
    uid: 0c5601ca-d6ab-4db7-8d8b-e18321e3e741
  resourceVersion: "2138"
  uid: f29089eb-f11e-4994-9b37-d87d50da41f9
spec:
  ...
  dnsPolicy: ClusterFirstWithHostNet
  enableServiceLinks: true
  hostNetwork: true
  ...
status:
  conditions:
  - lastProbeTime: null
    lastTransitionTime: "2024-09-18T03:37:31Z"
    status: "True"
    type: Initialized
  - lastProbeTime: null
    lastTransitionTime: "2024-09-18T03:38:50Z"
    status: "True"
    type: Ready
  - lastProbeTime: null
    lastTransitionTime: "2024-09-18T03:38:50Z"
    status: "True"
    type: ContainersReady
  - lastProbeTime: null
    lastTransitionTime: "2024-09-18T03:37:28Z"
    status: "True"
    type: PodScheduled
  containerStatuses:
  - containerID: containerd://146868dac3e14064117e31f4497ae6d7f19d3f0b876b0710945d039ff2baf404
   ...
    ready: true
    restartCount: 0
    started: true
    state:
      running:
        startedAt: "2024-09-18T03:37:31Z"
  hostIP: 193:116:66::2c
  initContainerStatuses:
  - containerID: containerd://d6829037467552e02fb4688872fdd5d6b19087a8320b2c03db75a9d2703231f0
    ...
    restartCount: 0
    started: false
    state:
      terminated:
        containerID: containerd://d6829037467552e02fb4688872fdd5d6b19087a8320b2c03db75a9d2703231f0
        exitCode: 0
        finishedAt: "2024-09-18T03:37:31Z"
        reason: Completed
        startedAt: "2024-09-18T03:37:31Z"
  phase: Running
  podIP: 193:116:66::2c
  podIPs:
  - ip: 193:116:66::2c
  - ip: 192.0.0.45
  qosClass: Burstable
  startTime: "2024-09-18T03:37:28Z"
```



### What did you expect to happen?

Service information can also be injected into the pod `assem-cic-kbbb8` environment variable.

### How can we reproduce it (as minimally and precisely as possible)?

deploy svc and pod

### Anything else we need to know?

_No response_

### Kubernetes version

<details>

```console
$ kubectl version
# paste output here
1.28.3
```

</details>


### Cloud provider

<details>
none
</details>


### OS version

<details>

```console
# On Linux:
$ cat /etc/os-release
# paste output here
$ uname -a
# paste output here

# On Windows:
C:\> wmic os get Caption, Version, BuildNumber, OSArchitecture
# paste output here
```

</details>


### Install tools

<details>

</details>


### Container runtime (CRI) and version (if applicable)

<details>

</details>


### Related plugins (CNI, CSI, ...) and versions (if applicable)

<details>

</details>