Skip to main content

Securing FastAPI Microservices with Kubernetes Secrets in Amazon EKS

Objective

This lab will help you secure sensitive information in your Amazon EKS Kubernetes cluster. By the end of it, you will be able to create Kubernetes secrets from an environment file and verify the creation of these secrets.

Prerequisites

Initial Setup

Navigate to the root directory of the python-fastapi-demo-docker project where your environment variables are sourced:

cd ~/environment/python-fastapi-demo-docker

1. Creating a Generic Kubernetes Secret from the .env File

Create the Kubernetes Secret in the my-cool-app namespace:

kubectl create secret generic fastapi-secret --from-env-file=.env -n my-cool-app

The expected output should look like this:

secret/fastapi-secret created

2. Verifying the Secret Creation with kubectl get secret

To confirm that your Kubernetes Secret has been successfully created, you can use kubectl get secrets to list all secrets that exist in the specified namespace:

kubectl get secrets -n my-cool-app

The expected output should look like this:

NAME             TYPE                             DATA   AGE
fastapi-secret Opaque 20 9m