Skip to main content

Stage 1: Liftoff

Page type · stage walkthrough

Where we left off​

  • Launchpad ran all ten components with Docker Compose on one machine. Compose gave us names (booking-db), environment variables and restart policies, but only on that one host.
  • Ignition built a three-node cluster and ran one bare Pod. When we deleted it, it stayed deleted: nothing in the cluster wanted it back.
  • So two gaps remain before Apollo can live on Kubernetes:
    • Nothing keeps Pods alive. A bare Pod is a one-off. Lose it and the airline loses that service.
    • Nothing gives Pods a stable address. Every replacement Pod gets a new IP. Booking cannot hard-code where flight lives.

Stage 1 closes both gaps, and moves the rest of what Compose did (config, secrets, start-up order) into Kubernetes objects.

What changes in this stage​

ConcernBefore (Launchpad / Ignition)Stage 1Why it's better
Keeping a service runningCompose restart: on one host; bare Pod in IgnitionDeployment → ReplicaSet → Pods (2 replicas per app)A controller compares desired vs actual and replaces lost Pods on any node
Finding another serviceCompose service name on a Docker networkService (booking, flight, …) with a label selectorOne stable name and virtual IP in front of changing Pod IPs
Reaching the app from your laptopCompose ports:NodePort Services (30080–30084)Works through kind's port mappings; good enough until Stage 2
Configurationenvironment: in docker-compose.ymlConfigMap apollo-airlines-configConfig lives outside the image and outside the Pod template; change it once for all apps
Passwords and JWT keyPlain env vars in ComposeSecret apollo-airlines-secretsSeparated from config so access can be controlled (still not encrypted: Stage 8)
"Who is this Pod?"Nothing13 ServiceAccounts, token automount offEach workload has its own identity, ready for RBAC later, with no API token it doesn't need
Loading seed datainit.sql mounted into Postgres in ComposeJobs init-*-db that run once to completionA one-shot task with retries and a clear Complete/Failed result
Database storageCompose named volume (survived restarts)emptyDirDeliberately a step backwards: it shows what Pod-scoped storage means before Stage 3 fixes it
Shipping a new versionRebuild and docker compose upRolling update with history and rollout undoOld Pods keep serving until new ones are ready; bad versions can be undone

What's in the folder​

PathWhat it isNew or replaces
k8s/config/namespace.yamlThe apollo-airlines NamespaceNew: a boundary for names, quotas and later policy
k8s/config/configmap.yamlPorts, DB names, service URLs, Redis URLReplaces Compose environment:
k8s/config/secrets.yamlPOSTGRES_PASSWORD, JWT_SECRETReplaces plain env vars
k8s/config/serviceaccounts.yamlOne ServiceAccount per workload and JobNew
k8s/infra/<db>/Postgres ×3 and Redis: Deployment + Service eachReplaces Compose database services
k8s/jobs/SQL in ConfigMaps + one Job per databaseReplaces Compose's init-script mount
k8s/apps/<service>/Six app Deployments + ServicesReplaces Compose app services; replaces Ignition's pod.yaml
k8s/kustomization.yamlLists every file aboveA single list for rendering; Kustomize proper comes in Stage 5
scripts/apply.shBuilds, loads and applies in dependency orderReplaces docker compose up
scripts/verify.sh, teardown.shFull check, and clean removal—

Walkthrough​

Step 1: Read one service end to end before applying anything​

Open k8s/apps/booking/booking-dep.yaml and booking-svc.yaml. The parts that matter:

# booking-dep.yaml (trimmed)
kind: Deployment
spec:
replicas: 2 # desired state: always two booking Pods
selector:
matchLabels: {app: booking} # "the Pods I own carry this label"
template: # the Pod shape the ReplicaSet stamps out
metadata:
labels: {app: booking} # must match the selector above
spec:
serviceAccountName: booking
containers:
- image: apollo11/booking:latest
ports: [{containerPort: 8082}]
env:
- name: POSTGRES_PASSWORD # from the Secret...
valueFrom: {secretKeyRef: {name: apollo-airlines-secrets, key: POSTGRES_PASSWORD}}
- name: DATABASE_URL # ...expanded here, so the password is never written down
value: "postgresql://postgres:$(POSTGRES_PASSWORD)@booking-db:5432/booking?sslmode=disable"
- name: FLIGHT_SERVICE_URL
valueFrom: {configMapKeyRef: {name: apollo-airlines-config, key: FLIGHT_SERVICE_URL}}
- name: JWT_SECRET
valueFrom: {secretKeyRef: {name: apollo-airlines-secrets, key: JWT_SECRET}}
readinessProbe: {httpGet: {path: /readyz, port: 8082}}
---
# booking-svc.yaml
kind: Service
spec:
type: NodePort
selector: {app: booking} # the same label again: this is the only link to the Pods
ports: [{port: 8082, targetPort: 8082, nodePort: 30082}]
  • What it is: the Ignition Pod, wrapped in a template, plus a controller that wants two copies of it, plus a stable name in front.
  • Why this way: the label app: booking appears three times. The Deployment uses it to find its Pods. The Service uses it to find where to send traffic. Neither one has a list of Pod names, because Pod names change. Labels are how Kubernetes connects things that come and go.
  • Compared with Ignition: pod.yaml was a single, named Pod. Here nobody writes a Pod by hand. You write the template, and the controller produces Pods from it.
  • Compared with Launchpad: in Compose, FLIGHT_SERVICE_URL=http://flight:8081 worked because of Docker's DNS. It still says http://flight:8081, but now flight is a Kubernetes Service name, resolved by cluster DNS. The app code did not change.
  • Watch out: Kubernetes does not check that these three labels agree. A typo is accepted and fails quietly. That is why the checks in "When something looks wrong" start with endpoints.

Step 2: Apply in dependency order​

kubectl config current-context # must be kind-apollo11
bash stages/stage1/scripts/apply.sh # add --skip-build to reuse loaded images

apply.sh runs six phases:

  1. Namespace, ConfigMap, Secret, ServiceAccounts.
  2. The three Postgres Deployments and Redis, with their Services.
  3. Wait for those to be ready.
  4. Run the three init-*-db Jobs and wait for Complete.
  5. The six application Deployments and Services.
  6. Wait for every rollout.
  • What happens: the script builds six images, loads them straight into the kind nodes (no registry yet), then applies files in that order.
  • Why the order matters: Kubernetes itself does not do ordering. If you apply everything at once, booking starts before its database exists, fails readiness, and keeps retrying. It would get there eventually, but the Jobs could fail first. The script waits at each boundary so every step starts on solid ground.
  • Compared with Launchpad: Compose's depends_on did a weaker version of this. In Kubernetes, the cluster is expected to converge on its own, and scripts (later Helm hooks and Argo sync waves) add ordering only where it really matters.
  • Why images are loaded, not pulled: there is no image registry yet. imagePullPolicy: IfNotPresent tells the kubelet to use the image already on the node. Stage 5 and the CI chapter introduce a registry.

Step 3: See the ownership chain that keeps Pods alive​

kubectl get deploy,rs,pods -n apollo-airlines -l app=booking
kubectl get rs -n apollo-airlines -l app=booking \
-o custom-columns='RS:.metadata.name,DESIRED:.spec.replicas,OWNER:.metadata.ownerReferences[0].name'
  • What you see: one Deployment, one ReplicaSet with a hash suffix, and two Pods whose names start with that ReplicaSet's name.
  • What it means:
    • The Deployment owns the ReplicaSet. It manages versions: each new Pod template gets a new ReplicaSet.
    • The ReplicaSet owns the Pods. It manages count: it keeps exactly replicas Pods matching its selector.
    • Each Pod carries an ownerReference pointing back up. Delete a Pod and its ReplicaSet notices the count is short and makes a new one, with a new name and a new UID.
  • Compared with Ignition: the bare Pod had no owner, so nothing noticed when it disappeared. Ownership is the difference.

Step 4: See how the Service finds Pods​

kubectl get svc booking -n apollo-airlines
kubectl get endpointslice -n apollo-airlines -l kubernetes.io/service-name=booking -o wide
kubectl get pods -n apollo-airlines -l app=booking -o wide
  • What you see: the Service has one ClusterIP that never changes. The EndpointSlice lists the two Pod IPs, which match the Pod list.
  • What it means: the Service keeps track of the Pods that match its selector and are Ready, and callers only ever use its name. That is all Stage 1 needs. How the list is kept and how packets reach a Pod is Stage 2.
  • Why readiness is involved: booking's /readyz checks its database and dependencies. A booking Pod that is running but can't reach its database is removed from the list, so it gets no traffic. A failing Pod stops receiving requests without anyone touching the Service.
  • Why NodePort here: type: NodePort also opens port 30082 on every node. kind maps that to localhost:30082, so you can reach booking from your laptop. It is a direct, crude door. Stage 2 explains it and replaces it with a proper entry point.
  • Why notification has no NodePort: only booking calls it. A service that nobody outside needs should not have a door to the outside.

Step 5: See configuration and identity arrive in the Pod​

kubectl get deploy booking -n apollo-airlines \
-o jsonpath='{range .spec.template.spec.containers[0].env[*]}{.name}{" <- "}{.valueFrom.configMapKeyRef.name}{.valueFrom.secretKeyRef.name}{"\n"}{end}'
kubectl get pod -n apollo-airlines -l app=booking -o jsonpath='{.items[0].spec.serviceAccountName}{"\n"}'
kubectl auth can-i get pods --as=system:serviceaccount:apollo-airlines:booking -n apollo-airlines # no
  • ConfigMap vs Secret: both become environment variables in the container. The split is about who may read them: later stages can let people read the ConfigMap but not the Secret. A Secret is only base64-encoded, not encrypted. Stage 8 introduces an external secret store.
  • One value built from another: identity, flight and booking read POSTGRES_PASSWORD from the Secret, then build DATABASE_URL as postgresql://postgres:$(POSTGRES_PASSWORD)@…. Kubernetes expands $(NAME) only for variables declared earlier in the same env list, so the order matters. The Secret stays the only copy of the password; the env listing above shows POSTGRES_PASSWORD <- apollo-airlines-secrets and an empty source for DATABASE_URL, because it is a plain value. Configuration and identity explains the expansion rules.
  • Env vars are read at start-up: if you change the ConfigMap, running Pods keep the old values until they restart. This is why config changes in later stages go with a rollout.
  • ServiceAccounts: each workload runs as its own identity (booking, booking-db, init-booking-db, …). None of them need to talk to the Kubernetes API, so automountServiceAccountToken: false keeps a usable token out of the container. Stage 8 grants real permissions with RBAC where they are needed.
  • Compared with Launchpad: Compose mixed config and secrets into one environment: block, and every container ran with the same (no) identity.

Step 6: See the Jobs that seeded the databases​

kubectl get jobs -n apollo-airlines
kubectl logs job/init-booking-db -n apollo-airlines
  • What a Job is: a controller for work that should finish. A Deployment restarts a container that exits. A Job counts an exit code 0 as success and stops.
  • How these Jobs work (init-booking-db.yaml):
    • Wait for pg_isready on booking-db, up to 30 tries.
    • Run psql -v ON_ERROR_STOP=1 -f /init/init.sql. The SQL is mounted from a ConfigMap.
    • backoffLimit: 3 with restartPolicy: Never: failed attempts leave Pods you can read logs from.
  • Why ON_ERROR_STOP: without it, a broken SQL file would still "succeed" and you would find out from empty tables later.

Step 7: Use the airline​

ComponentURL
Frontendhttp://localhost:30080 (log in as passenger@apolloairlines.com / pass123)
Flight APIhttp://localhost:30081/api/flights
Bookinghttp://localhost:30082/readyz
Identityhttp://localhost:30083/metrics
Searchhttp://localhost:30084/readyz
curl -s localhost:30081/api/flights | jq '.flights | length'

Make a booking in the UI. The request travels frontend → booking → identity and flight → booking-db → notification. Every hop is now a Service name resolved inside the cluster.

Step 8: See self-healing and a rolling update​

These are the two behaviours that Stage 1 exists for. Run them once and watch:

# Self-healing: delete a booking Pod and watch a new one appear
kubectl delete -n apollo-airlines --wait=false \
$(kubectl get pod -n apollo-airlines -l app=booking -o name | head -1)
kubectl get pods -n apollo-airlines -l app=booking -w # Ctrl-C after 2/2 Running

# Rolling update and rollback: ship a tag that doesn't exist, then undo it
kubectl set image deploy/search search=apollo11/search:missing-stage1-demo -n apollo-airlines
kubectl get rs,pods -n apollo-airlines -l app=search # new RS stuck in ImagePullBackOff, old Pods still serving
curl -s localhost:30084/readyz # still OK
kubectl rollout undo deploy/search -n apollo-airlines
kubectl rollout status deploy/search -n apollo-airlines
  • Self-healing: the deleted name is gone for good. The ReplicaSet made a new Pod to get back to two. That is reconciliation, the idea from Ignition, now doing real work.
  • The rollout: changing the image changes the Pod template, so the Deployment creates a second ReplicaSet and scales it up while scaling the old one down. With the default maxUnavailable setting, an old Pod is not removed until a new one is Ready. Because the new Pods never become Ready, the old ones keep serving. A bad release stalls instead of causing an outage.
  • rollout undo: points the Deployment back at the previous ReplicaSet's template. Nothing is rebuilt, the old ReplicaSet was kept for exactly this.
  • The warning rollout undo prints: kubectl v1.37+ warns that undo does not update the kubectl.kubernetes.io/last-applied-configuration annotation. That is expected. The live spec has rolled back; the next kubectl apply of the manifest (or apply.sh) brings the annotation back into agreement.

When something looks wrong​

You seeLikely causeFirst command
Pods Running, curl fails, no errors anywhereService selector or targetPort doesn't match the Podskubectl get endpointslice -n apollo-airlines -l kubernetes.io/service-name=<svc>
Pod 0/1 RunningReadiness failing, usually a dependencykubectl describe pod <pod> → Events, then /readyz
ImagePullBackOff / ErrImagePullImage tag not loaded into kindkubectl describe pod; rerun apply.sh
CrashLoopBackOffApp exits on start (bad env, DB unreachable)kubectl logs <pod> --previous
CreateContainerConfigErrorConfigMap or Secret key missingkubectl describe pod → Events
Job Failed, no flights in the APISeed SQL failedkubectl logs job/init-<name>-db

The troubleshooting page has more.

What this stage does not solve yet​

Limitation you can see nowWhy it hurtsFixed in
Delete booking-db's Pod and every booking is goneemptyDir lives and dies with the PodStage 3: PVCs and StatefulSets
Five NodePorts, one per service, plain HTTPNo single front door, no hostnames, no TLSStage 2: DNS, Ingress, Gateway API
Everything in one namespaceApps, UI and databases share one boundaryStage 2 splits into apollo-airlines-apps / -ui
Probes are basic; Pods have no resource requestsThe scheduler and kubelet are guessingStage 4: probes, requests/limits, PDBs
Thirty YAML files applied by a scriptRepeating values; no environments; no release historyStage 5: Helm, Kustomize, Argo CD
Secret is base64 in Git; no RBAC in useAnyone with repo access has the passwordStage 8 (planned): Vault, RBAC

The journey so far​

ConcernLaunchpadIgnitionStage 1
Runs onOne Docker hostThree-node kind clusterSame cluster
Unit of deploymentCompose serviceBare PodDeployment
Recoveryrestart: on one hostNoneReplicaSet replaces Pods
Service discoveryDocker DNSPod IP onlyService + cluster DNS
External accessports:kubectl port-forwardNodePort
Config / secretsenvironment:Inline in pod.yamlConfigMap / Secret
DataNamed volume—emptyDir (ephemeral)

Before you clean up: the flight deck​

Keep Stage 1 running for one more detour. Every check on this page was a kubectl command handed to you. The flight deck tutorials teach the tools behind them, on this running airline:

TutorialWhat you get out of it
kubectl: zero to heroWrite your own commands: discover types and fields, select, shape output, watch, preview changes
Contexts and a second clusterRun a side apollo11-sandbox cluster and always know which cluster a command hits
k9sSteps 3–8's checks (and Ignition's) in a keyboard-driven terminal UI
HeadlampThe same checks in a graphical UI, with a map of Deployments, ReplicaSets, Pods and Services

They only look; nothing in them changes Apollo. Come back here when you are done.

Clean up​

bash stages/stage1/scripts/verify.sh --context kind-apollo11 # optional: the full automated check
bash stages/stage1/scripts/teardown.sh
kubectl get ns apollo-airlines # NotFound
kubectl config set-context --current --namespace=default # reset context namespace if altered during Flight Deck

The kind cluster stays for Stage 2.

You should now be able to explain​

  • Why a deleted booking Pod comes back with a new name, when Ignition's Pod did not.
  • How a Service finds its Pods, and why a label typo fails without an error.
  • Why a broken image tag stalls the rollout instead of taking search down.
  • What rollout undo actually switches back.
  • Why config and secrets are separate objects, and what a Secret does not protect.
  • Why booking's data disappears when its database Pod is replaced.

Next: if you skipped it, take the flight deck first. Then Stage 2: Guidance replaces five NodePorts with names, hostnames and a real front door.