Communicating with Other Pods in Kubernetes

2023-10-07 09:46 (2 years ago)
Names in the Namespace
Play a song themed on this article

If it is within the same namespace, name resolution can be done using the metadata.name of the Service.

Service

apiVersion: v1
kind: Service
metadata:
  name: redis
  namespace: airflow
spec:
  ports:
    - name: "6379"
      port: 6379
      targetPort: 6379

With this configuration, you can resolve the name redis from other Pods.

redis://:@redis:6379/0

Similarly,

apiVersion: v1
kind: Service
metadata:
  name: postgres
  namespace: airflow
spec:
  ports:
    - name: "5432"
      port: 5432
      targetPort: 5432

With this setup, you can resolve the name postgres as follows:

db+postgresql://username:password@postgres/airflow
postgresql+psycopg2://username:password@postgres/airflow

Categories

Archive