Service Links — auto-inject environment variables for Services.
1apiVersion: v12kind: Pod3metadata:4 name: my-pod5spec:6 enableServiceLinks: false # Disable service links7 containers:8 - name: app9 image: nginx:latest10---11# Default behavior (enableServiceLinks: true)12apiVersion: v113kind: Pod14metadata:15 name: pod-with-links16spec:17 enableServiceLinks: true # Default18 containers:19 - name: app20 image: nginx:latest
1# Check service links2kubectl exec pod-with-links -- env | grep SERVICE34# Example environment variables injected:5# MY_SERVICE_SERVICE_HOST=10.96.0.106# MY_SERVICE_SERVICE_PORT=807# MY_SERVICE_PORT=tcp://10.96.0.10:808# MY_SERVICE_PORT_80_TCP=tcp://10.96.0.10:809# MY_SERVICE_PORT_80_TCP_PROTO=tcp10# MY_SERVICE_PORT_80_TCP_PORT=8011# MY_SERVICE_PORT_80_TCP_ADDR=10.96.0.101213# Check if service links are enabled14kubectl get pod my-pod -o jsonpath='{.spec.enableServiceLinks}'1516# Count injected variables17kubectl exec pod-with-links -- env | grep SERVICE | wc -l
Behavior:
Best Practices: