Kubernetes. Could not translate host name "pg" to address: Temporary failure in name resolution

Всем привет. Деплою приложение Django в Kubernetes. Когда хочу провести миграции в контейнере. Выходит ошибка что не резолвит dns "pg". Как это пофиксить?

    root@ktswebinar-6b7c46b449-286rr:/code# python manage.py makemigrations
    /usr/local/lib/python3.9/site-packages/django/core/management/commands/makemigrations.py:105: RuntimeWarning: Got an error checking a consistent migration history performed for database connection 'default': could not translate host name "pg" to address: Temporary failure in name resolution
    
      warnings.warn(
    No changes detected
    root@ktswebinar-6b7c46b449-286rr:/code# 


  root@kube-master:/home/dott/job# kubectl -n ktswebinar get service
NAME   TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)    AGE
pg     ClusterIP   10.100.6.148   <none>        5432/TCP   17h   


My manifest

root@kube-master:/home/dott/job# ls
app-deploy.yaml  app-migrations1.yaml  pg-deploy.yaml  pg-service.yaml

root@kube-master:/home/dott/job# nano app-deploy.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: ktswebinar
  labels:
    app.kubernetes.io/name: ktswebinar
    app.kubernetes.io/component: web
spec:
  replicas: 1
  selector:
    matchLabels:
      app.kubernetes.io/name: ktswebinar
      app.kubernetes.io/component: web
  template:
    metadata:
      labels:
        app.kubernetes.io/name: ktswebinar
        app.kubernetes.io/component: web
    spec:
      containers:
        - name: ktswebinar
          image: igorcoding/ktswebinar:1.0.4
          imagePullPolicy: IfNotPresent
          ports:
            - containerPort: 8000
              name: http
          env:
            - name: DATABASE_URL
              value: postgresql://postgres:gYwOKJZaR0do8TUUgPS9@pg:5432/postgres


root@kube-master:/home/dott/job# nano app-migrations1.yaml
apiVersion: batch/v1
kind: Job
metadata:
  name: migrations
  labels:
    app.kubernetes.io/name: ktswebinar
    app.kubernetes.io/component: migrations
spec:
  activeDeadlineSeconds: 120
  template:
    metadata:
      labels:
        app.kubernetes.io/name: ktswebinar
        app.kubernetes.io/component: migrations
    spec:
      restartPolicy: Never
      containers:
        - name: migrations
          image: igorcoding/ktswebinar:1.0.4
          imagePullPolicy: IfNotPresent
          command:
            - python
            - manage.py
            - migrate
          env:
            - name: DATABASE_URL
              value: postgresql://postgres:gYwOKJZaR0do8TUUgPS9@pg:5432/postgres


root@kube-master:/home/dott/job# nano pg-deploy.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: pg
  labels:
    app.kubernetes.io/name: ktswebinar
    app.kubernetes.io/component: pg
spec:
  replicas: 1
  selector:
    matchLabels:
      app.kubernetes.io/name: ktswebinar
      app.kubernetes.io/component: pg
  template:
    metadata:
      labels:
        app.kubernetes.io/name: ktswebinar
        app.kubernetes.io/component: pg
    spec:
      containers:
        - name: pg
          image: postgres:14
          imagePullPolicy: IfNotPresent
          ports:
            - containerPort: 5432
              name: pg
          env:
            - name: POSTGRES_PASSWORD
              value: gYwOKJZaR0do8TUUgPS9



root@kube-master:/home/dott/job# nano pg-service.yaml


apiVersion: v1
kind: Service
metadata:
  name: pg
  labels:
    app.kubernetes.io/name: ktswebinar
    app.kubernetes.io/component: pg
spec:
  type: ClusterIP
  ports:
    - port: 5432
      targetPort: pg
      protocol: TCP
      name: pg
  selector:
    app.kubernetes.io/name: ktswebinar
    app.kubernetes.io/component: pg


root@kube-master:/home/dott/job# kubectl -n ktswebinar get pods
NAME                          READY   STATUS    RESTARTS   AGE
ktswebinar-6b7c46b449-286rr   1/1     Running   0          42s
pg-56c9d89c69-mljlh           1/1     Running   0          116s

Ответы (0 шт):