Why I can't connect AWS RDS with rake. on EKS

I asked here. I don’t know how it works so I would like to know. Why I can't connect AWS RDS with rake. on EKS · Issue #49402 · rails/rails · GitHub.

Steps to reproduce

First, I’m a biginner for ruby.

# database.yml
staging:
  primary:
    adapter: postgis
    encoding: utf8
    database: <%= ENV['DATABASE_NAME'] %>
    pool: 5
    username: <%= ENV['DATABASE_USER'] %>
    password: <%= ENV['DATABASE_PASSWORD'] %>
    host: <%= ENV['DATABASE_HOST'] %>
    port: 5432
# migration.yml
apiVersion: batch/v1
kind: Job
metadata:
  name: testmigration
spec:
  backoffLimit: 3
  completions: 1
  template:
    spec:
      containers:
      - command:
        - bash
        - -c
        - |
          set -e

          # db create
          rake db:exists || rake db:create
          echo "creation completed" # created "test_db"

          # migrate
          rake db:migrate
          echo "migration completed"

        env:
        - name: DATABASE_PASSWORD
          value: <password>
        - name: DATABASE_USER
          value: "test_user"
        - name: DATABASE_HOST
           value: "RDS_HOST_NAME"
        - name: DATAABSE_NAME
           value: "test_db"
        - name: RAILS_ENV
           value: "staging"
        image: "my-image"
        name: migration

then, execute kubectl apply -f migration.yml.

Expected behavior

migration completed with no error.

Actual behavior

I got logs with kubectl logs as follows.

could not connect to server: No such file or directory
	Is the server running locally and accepting
	connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
Couldn't create 'app' database. Please check your configuration.
rake aborted!
ActiveRecord::NoDatabaseError: could not connect to server: No such file or directory
	Is the server running locally and accepting
	connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

Caused by:
PG::ConnectionBad: could not connect to server: No such file or directory
	Is the server running locally and accepting
	connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
Created database 'test_db'

so why rake task has connect local db? In the first place any settings are wrong?

But I can create db successfuly.

System configuration

Rails version: rails (6.1.7.4)

Ruby version: ruby 3.0.6p216

does the error message change when you replace adapter: postgis with adapter: postgresql

is this wrong on db:exists?

Error message has no changes. What I should focus?

I executed ActiveRecord::Base.connection_db_config in rails console.

#<ActiveRecord::DatabaseConfigurations::HashConfig:xxx 
@env_name="staging", 
@name="primary",
@configuration_hash={:adapter=>"postgis", :encoding=>"utf8", :database=>"test_db", :pool=>5, :username=>"test_user", :password=>"<password>", :host=>"<host>", :port=>5432}>

Response is correct. but my rake task connect to local. Why?

maybe, rake task is wrong.
The results for executed rake -T.

db:create
db:create:primary
....

db:create is connect to local as default?
db:create:primary is seems to ok.

then, I can successfully until db:migrate. But, db:seed was failed as follows.

rake aborted!
ActiveRecord::ConnectionNotEstablished: could not connect to server: No such file or directory
	Is the server running locally and accepting
	connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

Caused by:
PG::ConnectionBad: could not connect to server: No such file or directory
	Is the server running locally and accepting
	connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
....
Tasks: TOP => db:abort_if_pending_migrations

db:abort_if_pending_migrations doesn’t exists in result of rake -T.
What a happend?

What are the differences or considerations when connecting Rake to an AWS RDS instance in a VPC versus a non-VPC setup on EKS?