podman pod createpodman kube playoc new-appoc create secretoc set env| Question | Typical Answer |
|---|---|
| How do components talk to each other? | Over the network, by Service name |
| Which components keep data? | Usually only the database, on a persistent volume |
| Where do settings and credentials go? | In ConfigMaps and Secrets, not the image |
| Which components do users reach? | Usually only the front end |
Every Service gets a DNS name inside the cluster, so components find each other by name:
| Name | Resolves From |
|---|---|
inventory-db | Pods in the same project |
inventory-db.myproject | Pods in other projects |
inventory-db.myproject.svc.cluster.local | Anywhere in the cluster (fully qualified) |
$ podman pod create --name myapp -p 8080:8080 $ podman run -d --pod myapp --name front quay.io/example/frontend $ podman run -d --pod myapp --name back quay.io/example/backend
localhost, on their own ports.# Generate Kubernetes YAML from the running pod $ podman kube generate myapp > myapp.yaml # Recreate the pod from that YAML, locally $ podman pod rm -f myapp $ podman kube play myapp.yaml
The same YAML is a starting point for the cluster. In OpenShift, each component usually gets its own Deployment, so they can scale separately.
| Component | Deployment | Service | Route |
|---|---|---|---|
frontend | ✓ | ✓ | ✓ |
backend | ✓ | ✓ | — |
inventory-db | ✓ | ✓ (plus a PVC) | — |
$ oc new-app --name=frontend quay.io/example/frontend
$ oc new-app --name=backend quay.io/example/backend
$ oc expose service frontend # the only Route
# In the frontend Deployment's env, reference the database Service by name env: - name: DB_HOST value: "inventory-db" # resolves via cluster DNS to the database Service - name: DB_PORT value: "5432"
The front end never needs to know where the database pod is running. Cluster DNS turns inventory-db into the Service's stable address.
# Non-sensitive settings $ oc create configmap frontend-config \ --from-literal=DB_HOST=inventory-db --from-literal=DB_PORT=5432 # Credentials $ oc create secret generic db-creds \ --from-literal=DB_USER=app --from-literal=DB_PASSWORD='S3cret!' # Inject both into the Deployment as environment variables $ oc set env deployment/frontend --from=configmap/frontend-config $ oc set env deployment/frontend --from=secret/db-creds