You have kubectl. You have AWS RDS. You want IAM authentication. You want to connect without scattering database credentials in configs or secrets across clusters. The shortest path is to let Kubernetes and AWS IAM handle the trust, then connect to your database like you own it — because you do.
Why Kubectl AWS RDS IAM Connect Works
When AWS RDS integrates with IAM, authentication shifts from static credentials to ephemeral tokens. They expire in minutes. That means no long-lived passwords, no accidental leaks in code repos, no vault maintenance just to keep basic auth alive.
kubectl lets you run commands inside a pod that holds the right IAM role. With aws rds generate-db-auth-token, you generate a token tied to the role’s policy. That token becomes your password, valid just long enough to connect.
The Direct Steps to Set It Up
- Enable IAM DB Authentication
In the RDS console or via AWS CLI, make sure your DB instance has--enable-iam-database-authenticationturned on. Apply pending modifications and restart if needed. - Grant IAM Permissions
Attach a policy to the role used by your Kubernetes pod. It needsrds-db:connectplus standard network permissions to reach the DB. - Update DB Users
In your RDS database, create or modify the user withIDENTIFIED WITH AWSAuthenticationPlugin AS 'RDS'(for MySQL) orrds_iam(for PostgreSQL). Grant application-level privileges as usual. The username must match the IAM role user name. - Generate the Auth Token with Kubectl
Usekubectl execto run:
aws rds generate-db-auth-token \
--hostname <endpoint> \
--port 5432 \
--region <region> \
--username <db_user>
This command uses your pod’s IAM role to create a secure, time-limited token.