containers:
- name: fastapi-service
image: DOCKER_USERNAME/REPO_NAME
imagePullPolicy: Always
env:
- name: POSTGRES_PASSWORD
valueFrom:
secretKeyRef:
name: postgres-secret
key: POSTGRES_PASSWORD
- name: POSTGRES_USER
value: postgres
- name: POSTGRES_DB
value: example
- name: POSTGRES_SERVER
value: postgres
- name: POSTGRES_PORT
value: "5432"
ports:
- containerPort: 8001
---
apiVersion: v1
kind: Service
metadata:
name: service-entrypoint
namespace: default
spec:
type: NodePort
selector:
service: fastapi
ports:
- port: 8001
targetPort: 8001
nodePort: 30001
```
In these Kubernetes YAML file, there are various objects, separated by the `---`:
- A Deployment, describing a scalable group of identical pods. In this case,
you'll get just one replica, or copy of your pod. That pod, which is
described under `template`, has just one container in it. The
container is created from the image built by GitHub Actions in [Configure CI/CD for
your Python application](configure-github-actions.md).
- A Service, which will define how the ports are mapped in the containers.
- A PersistentVolumeClaim, to define a storage that will be persistent through restarts for the database.
- A Secret, Keeping the database password as an example using secret kubernetes resource.
- A NodePort service, which will route traffic from port 30001 on your host to
port 8001 inside the pods it routes to, allowing you to reach your app
from the network.
To learn more about Kubernetes objects, see the [Kubernetes documentation](https://kubernetes.io/docs/home/).
> [!NOTE]
>
> - The `NodePort` service is good for development/testing purposes. For production you should implement an [ingress-controller](https://kubernetes.io/docs/concepts/services-networking/ingress-controllers/).
## Deploy and check your application
1. In a terminal, navigate to `python-docker-dev-example` and deploy your database to
Kubernetes.
```console
$ kubectl apply -f docker-postgres-kubernetes.yaml
```
You should see output that looks like the following, indicating your Kubernetes objects were created successfully.
```console
deployment.apps/postgres created