> ## Documentation Index
> Fetch the complete documentation index at: https://docs.formae.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Deploy the bookstore on GKE

> A GCP infrastructure pattern, deployed with formae.

A full-stack workload that provisions its own managed cluster. This example
ships with the formae Kubernetes plugin and selects GCP by applying its
`gcp.pkl` entry file. One forma provisions the cluster side (a project IAM grant,
a VPC, a subnet, a Cloud Router, a Cloud NAT, and a Standard zonal GKE cluster)
and, through a Kubernetes target authenticated against that cluster's endpoint,
the workload side (a namespace, config maps, a secret, a service account, an
nginx frontend and Node.js backend deployment, and their services). It needs
`GCP_PROJECT` and `GCP_APPLY_AS` set so the cluster and the IAM grant resolve.

```mermaid theme={"languages":{"custom":["/languages/pkl.json"]}}
flowchart LR
  gcpTgt["gcp-target-bookstore"]:::tgt
  k8sTgt["k8s-target-gcp-bookstore"]:::tgt

  subgraph stack["k8s-bookstore-gcp"]
    direction LR
    iam["Project IAM member"]:::res
    vpc["VPC network"]:::res
    subnet["Subnet"]:::res
    router["Cloud Router"]:::res
    nat["Cloud NAT"]:::res
    gke["GKE cluster"]:::res
    ns["Namespace"]:::res
    feConfig["Frontend config map"]:::res
    beConfig["Backend config map"]:::res
    dbSecret["DB credentials secret"]:::res
    beSa["Backend service account"]:::res
    feDeploy["Frontend deployment"]:::res
    beDeploy["Backend deployment"]:::res
    feSvc["Frontend load balancer service"]:::res
    beSvc["Backend service"]:::res

    vpc --> subnet
    vpc --> router
    router --> nat
    vpc --> gke
    subnet --> gke
    ns --> feConfig
    ns --> beConfig
    ns --> dbSecret
    ns --> beSa
    ns --> feDeploy
    ns --> beDeploy
    ns --> feSvc
    ns --> beSvc
    iam --> gke
  end

  gcpTgt --> stack
  gke --> k8sTgt
  k8sTgt --> ns

  classDef tgt fill:#FF8201,stroke:#B25900,color:#ffffff
  classDef res fill:#FFF3E6,stroke:#FF8201,color:#02024B
  style stack fill:#ffffff,stroke:#02024B,stroke-width:2px,stroke-dasharray:6 4,color:#02024B
```

**Deploy.** Apply the GCP entry file. formae provisions the cloud infrastructure
first, then authenticates the Kubernetes target against the new cluster's
endpoint and rolls out the workload:

```bash theme={"languages":{"custom":["/languages/pkl.json"]}}
formae apply --mode reconcile \
  /opt/pel/formae/examples/formae-plugin-kubernetes/bookstore/gcp.pkl
```

**Verify.** Once the command completes, the stack's resources are under
management:

```bash theme={"languages":{"custom":["/languages/pkl.json"]}}
formae inventory resources --query="stack:k8s-bookstore-gcp"
```

**Tear down.** Remove everything the forma created. The GKE cluster has
dependents, so cascade the destroy:

```bash theme={"languages":{"custom":["/languages/pkl.json"]}}
formae destroy --on-dependents=cascade \
  /opt/pel/formae/examples/formae-plugin-kubernetes/bookstore/gcp.pkl
```

The full forma is in the
[bookstore example](https://github.com/platform-engineering-labs/formae-plugin-kubernetes/tree/main/examples/bookstore).
