Another way to find services is through environment variables. Every container that Kubernetes creates will have environment variables that can be used to find every service that is currently running in the cluster. For example, if we use the env command to print all the environment variables with the HELLOK8S string, that’s what we get:
xxxxxxxxxx
apiVersion: apps/v1
kind: Deployment
metadata:
name: hellok8s
spec:
replicas: 2
selector:
matchLabels:
app: hellok8s
template:
metadata:
labels:
app: hellok8s
spec:
containers:
- image: brianstorti/hellok8s:v3
name: hellok8s-container