Overview & What's Different
Welcome back
In the beginner codelab, you used kubectl commands to deploy a simple hello-world app. That's a great starting point but real production apps are managed very differently.
In this codelab you'll deploy a real-world Node.js web app the way engineers actually do it: using YAML manifests, ConfigMaps & Secrets for configuration, and Helm to package and manage everything as a reusable chart.
What's new in this codelab
| Beginner Codelab | This Intermediate Codelab |
|---|---|
| kubectl imperative commands | NEW Declarative YAML manifests |
| hello-world sample image | NEW Real Node.js web app |
| Config hardcoded in image | NEW ConfigMaps & Secrets |
| Manual kubectl apply | NEW Helm chart packaging |
| One-off deploy | NEW Versioned, repeatable releases |
What you'll learn
- Write and understand real Kubernetes YAML manifests
- Store app config in ConfigMaps and sensitive data in Secrets
- Inject config into Pods as environment variables
- Understand what Helm is and why teams use it
- Create a Helm chart for your app from scratch
- Deploy, upgrade, rollback, and uninstall with Helm
What you'll build
APP_ENV, APP_PORT
DB_PASSWORD
Before You Begin
Prerequisites
- Completed the Beginner GKE Codelab you should be comfortable with Pods, Deployments, Services
- A Google Cloud project with billing enabled
- Kubernetes Engine API enabled
Open Cloud Shell & create your cluster
Open Cloud Shell and create a fresh cluster:
gcloud container clusters create my-app-cluster \ --num-nodes=2 \ --zone=us-central1-a \ --machine-type=e2-medium gcloud container clusters get-credentials my-app-cluster \ --zone=us-central1-a
Install Helm
Helm is the package manager for Kubernetes. Cloud Shell doesn't have it pre-installed, so let's add it:
# Download and install Helm curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash # Verify installation helm version
You should see output like version.BuildInfo{Version:"v3.x.x"...}
Once your cluster is RUNNING and helm version works, you're set. Let's look at the app we're deploying.
The App We're Building
Meet the app: node-webapp
Instead of a one-line hello-world, we're deploying a small Node.js web server that reads its configuration from environment variables the way real 12-factor apps are built.
The app reads three values from its environment:
| Variable | Source | Description |
|---|---|---|
APP_ENV | ConfigMap | e.g. production or staging |
APP_PORT | ConfigMap | Port the server listens on |
DB_PASSWORD | Secret | Sensitive credential — never hardcoded |
The app source code
We'll use a pre-built public image. Here's what the source looks like notice how it reads config from process.env:
// A real-world Node.js app that reads config from environment
const http = require('http');
const PORT = process.env.APP_PORT || 8080;
const ENV = process.env.APP_ENV || 'development';
const DB_PASS = process.env.DB_PASSWORD ? '***hidden***' : 'not set';
const server = http.createServer((req, res) => {
res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({
message: 'Hello from node-webapp!',
env: ENV,
port: PORT,
db_pass: DB_PASS,
hostname: require('os').hostname(),
version: '1.0.0'
}, null, 2));
});
server.listen(PORT, () => {
console.log(`Server running in ${ENV} mode on port ${PORT}`);
});
The 12-factor app methodology says config that changes between environments (dev/staging/prod) should come from the environment — never hardcoded in code. Kubernetes ConfigMaps and Secrets are the standard way to inject this config into your Pods.
Project structure we'll create
node-webapp/ ├── manifests/ # Raw YAML — Step 4 & 5 │ ├── configmap.yaml │ ├── secret.yaml │ ├── deployment.yaml │ └── service.yaml └── helm/ # Helm chart — Step 8 & 9 └── node-webapp/ ├── Chart.yaml ├── values.yaml └── templates/ ├── configmap.yaml ├── secret.yaml ├── deployment.yaml └── service.yaml
# Create the folder structure
mkdir -p node-webapp/manifests
mkdir -p node-webapp/helm/node-webapp/templates
cd node-webapp
YAML Manifests Deep Dive
Imperative vs Declarative
In the beginner codelab you used imperative commands like kubectl create deployment .... That's fine for learning, but professionals use declarative YAML files.
| Imperative (beginner) | Declarative YAML (production) |
|---|---|
| Tell Kubernetes what to do | Tell Kubernetes what you want |
kubectl create deployment ... | kubectl apply -f deployment.yaml |
| Hard to track changes | Lives in Git — full history |
| Can't easily recreate | Idempotent run it 100 times, same result |
| No code review possible | PRs, reviews, approvals |
Anatomy of a Deployment YAML
Every Kubernetes YAML file has 4 top-level fields. Let's write our Deployment and understand each line:
apiVersion: apps/v1 # Which Kubernetes API to use kind: Deployment # What kind of object this is metadata: # Name and labels for this object name: node-webapp labels: app: node-webapp spec: # The desired state you want replicas: 3 selector: matchLabels: app: node-webapp # Must match template labels below template: # Blueprint for each Pod metadata: labels: app: node-webapp spec: containers: - name: node-webapp image: gcr.io/google-samples/hello-app:1.0 ports: - containerPort: 8080 envFrom: # Inject ALL keys from ConfigMap - configMapRef: name: webapp-config env: # Inject specific Secret keys - name: DB_PASSWORD valueFrom: secretKeyRef: name: webapp-secret key: db-password resources: # Always set resource limits! requests: memory: "64Mi" cpu: "100m" limits: memory: "128Mi" cpu: "200m"
cpu: "100m"?m stands for millicores. 1000m = 1 full CPU core. So 100m means this container requests 10% of a CPU. Always set both requests (guaranteed) and limits (maximum) without them your Pod can starve other Pods or get killed during node pressure.
The Service YAML
apiVersion: v1 kind: Service metadata: name: node-webapp-svc spec: type: LoadBalancer selector: app: node-webapp # Routes to Pods with this label ports: - protocol: TCP port: 80 # External port (what users hit) targetPort: 8080 # Container port (matches containerPort above)
The selector.app: node-webapp in the Service must exactly match the labels.app: node-webapp in the Deployment template. This is how Kubernetes knows which Pods belong to which Service it's just label matching.
ConfigMaps & Secrets
What's the difference?
| ConfigMap | Secret | |
|---|---|---|
| Use for | Non-sensitive config (env name, ports, feature flags) | Sensitive data (passwords, API keys, tokens) |
| Storage | Plain text in etcd | Base64-encoded in etcd (+ optional encryption) |
| Access control | Any Pod in namespace | RBAC-restricted, only authorized Pods |
| In Git? | ✅ Safe to commit | ❌ Never commit use Sealed Secrets or GCP Secret Manager |
Create the ConfigMap
ConfigMaps store plain key-value pairs. Our app will read APP_ENV and APP_PORT from this:
apiVersion: v1 kind: ConfigMap metadata: name: webapp-config namespace: default data: APP_ENV: "production" APP_PORT: "8080" LOG_LEVEL: "info"
Create the Secret
Secrets store sensitive values. The values must be base64-encoded. Let's encode our password first:
# Encode your secret value to base64 echo -n "my-super-secret-db-password" | base64 # Output: bXktc3VwZXItc2VjcmV0LWRiLXBhc3N3b3Jk
Now paste that base64 value into your Secret YAML:
apiVersion: v1 kind: Secret metadata: name: webapp-secret namespace: default type: Opaque data: # Value must be base64 encoded db-password: bXktc3VwZXItc2VjcmV0LWRiLXBhc3N3b3Jk
Base64 is not encryption it's just encoding. Anyone can decode it instantly with echo "..." | base64 -d. Add secret.yaml to your .gitignore. In production, use GCP Secret Manager or Sealed Secrets.
How the Pod reads them
Look back at the Deployment YAML from Step 4. There are two ways to inject config:
# Pattern 1: envFrom inject ALL keys from a ConfigMap as env vars envFrom: - configMapRef: name: webapp-config # Result: APP_ENV=production, APP_PORT=8080, LOG_LEVEL=info --- # Pattern 2: env inject ONE specific key from a Secret env: - name: DB_PASSWORD valueFrom: secretKeyRef: name: webapp-secret key: db-password # Result: DB_PASSWORD=my-super-secret-db-password (decoded)
Kubernetes automatically decodes the base64 value before injecting it into the container. Your app code simply reads process.env.DB_PASSWORD and gets the plain text value.
Deploy with kubectl apply
Create all the YAML files
Run these commands in Cloud Shell to create all four manifest files at once:
cat > manifests/configmap.yaml << 'EOF' apiVersion: v1 kind: ConfigMap metadata: name: webapp-config data: APP_ENV: "production" APP_PORT: "8080" LOG_LEVEL: "info" EOF
cat > manifests/secret.yaml << 'EOF' apiVersion: v1 kind: Secret metadata: name: webapp-secret type: Opaque data: db-password: bXktc3VwZXItc2VjcmV0LWRiLXBhc3N3b3Jk EOF
cat > manifests/deployment.yaml << 'EOF'
apiVersion: apps/v1
kind: Deployment
metadata:
name: node-webapp
labels:
app: node-webapp
spec:
replicas: 3
selector:
matchLabels:
app: node-webapp
template:
metadata:
labels:
app: node-webapp
spec:
containers:
- name: node-webapp
image: gcr.io/google-samples/hello-app:1.0
ports:
- containerPort: 8080
envFrom:
- configMapRef:
name: webapp-config
env:
- name: DB_PASSWORD
valueFrom:
secretKeyRef:
name: webapp-secret
key: db-password
resources:
requests:
memory: "64Mi"
cpu: "100m"
limits:
memory: "128Mi"
cpu: "200m"
EOF
cat > manifests/service.yaml << 'EOF'
apiVersion: v1
kind: Service
metadata:
name: node-webapp-svc
spec:
type: LoadBalancer
selector:
app: node-webapp
ports:
- protocol: TCP
port: 80
targetPort: 8080
EOF
Apply everything at once
With kubectl apply -f, you can point at an entire directory:
kubectl apply -f manifests/
# Expected output:
# configmap/webapp-config created
# secret/webapp-secret created
# deployment.apps/node-webapp created
# service/node-webapp-svc created
Verify everything is running
# Check all pods are Running kubectl get pods # Check the ConfigMap was created kubectl get configmap webapp-config # Check the Secret was created kubectl get secret webapp-secret # Watch for the external IP kubectl get service node-webapp-svc --watch
Inspect the config inside a running Pod
Once a Pod is running, you can verify it received the config correctly:
# Get the name of one pod POD=$(kubectl get pods -l app=node-webapp -o jsonpath='{.items[0].metadata.name}') # Print environment variables inside the pod kubectl exec $POD -- env | grep -E "APP_ENV|APP_PORT|DB_PASSWORD" # Expected: # APP_ENV=production # APP_PORT=8080 # DB_PASSWORD=my-super-secret-db-password
You've deployed a real app using declarative YAML, with config injected from a ConfigMap and a Secret. This is production-grade Kubernetes. Next let's package all of this into a Helm chart.
Introduction to Helm
What is Helm?
You just wrote 4 YAML files to deploy one app. Imagine managing 10 apps, each needing their own configmap, secret, deployment, service, ingress... That's 50+ files. And what if you need to deploy the same app to dev, staging, and prod with slightly different values?
Helm is the package manager for Kubernetes. It lets you bundle all your Kubernetes manifests into a single reusable Chart, and customize them for different environments using a single values.yaml file.
📦 The apt/npm Analogy
Helm is to Kubernetes what apt is to Ubuntu or npm is to Node.js. Instead of manually downloading and configuring software, you run helm install my-app ./my-chart and everything is set up correctly. You can also install community charts: helm install nginx ingress-nginx/ingress-nginx.
Core Helm concepts
| Term | What it is |
|---|---|
| Chart | A package of Kubernetes YAML templates + a values.yaml |
| values.yaml | Default configuration values for the chart |
| Release | A deployed instance of a chart. You can deploy the same chart multiple times with different names. |
| Template | A YAML file with {{ .Values.something }} placeholders that get filled in at deploy time |
| Repository | A collection of published charts (like npmjs.com but for Helm) |
The Helm workflow
your config
your YAML templates
rendered manifests applied
Essential Helm commands
# Install a chart (create a new release) helm install <release-name> <chart-path> # Install with custom values helm install <release-name> <chart-path> --set key=value # Upgrade an existing release (rolls out changes) helm upgrade <release-name> <chart-path> # Roll back to a previous version helm rollback <release-name> <revision> # List all releases in the cluster helm list # See the history of a release helm history <release-name> # Remove a release (deletes all its Kubernetes objects) helm uninstall <release-name>
Both apply Kubernetes manifests, but Helm additionally tracks release history, supports one-command rollback, and lets you parameterize everything via values.yaml. Teams use Helm for anything they'll deploy more than once.
Package App as a Helm Chart
Scaffold the chart structure
# Create the chart skeleton helm create helm/node-webapp # Remove the default boilerplate templates rm -rf helm/node-webapp/templates/* rm helm/node-webapp/templates/.gitkeep 2>/dev/null; true # List what was created ls helm/node-webapp/
Chart.yaml chart metadata
cat > helm/node-webapp/Chart.yaml << 'EOF' apiVersion: v2 name: node-webapp description: A real-world Node.js web app deployed on GKE type: application version: 0.1.0 # Chart version appVersion: "1.0.0" # Your app version EOF
values.yaml all configurable defaults
This is the heart of Helm. Everything that might change between environments goes here:
cat > helm/node-webapp/values.yaml << 'EOF' # Deployment settings replicaCount: 3 image: repository: gcr.io/google-samples/hello-app tag: "1.0" # App configuration (goes into ConfigMap) config: appEnv: "production" appPort: "8080" logLevel: "info" # Sensitive values (goes into Secret) secret: dbPassword: "bXktc3VwZXItc2VjcmV0LWRiLXBhc3N3b3Jk" # Service settings service: type: LoadBalancer port: 80 targetPort: 8080 # Resource limits resources: requests: memory: "64Mi" cpu: "100m" limits: memory: "128Mi" cpu: "200m" EOF
Templates YAML with placeholders
Now convert your static manifests into templates using {{ .Values.xxx }} syntax:
cat > helm/node-webapp/templates/configmap.yaml << 'EOF'
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ .Release.Name }}-config
data:
APP_ENV: {{ .Values.config.appEnv | quote }}
APP_PORT: {{ .Values.config.appPort | quote }}
LOG_LEVEL: {{ .Values.config.logLevel | quote }}
EOF
cat > helm/node-webapp/templates/secret.yaml << 'EOF'
apiVersion: v1
kind: Secret
metadata:
name: {{ .Release.Name }}-secret
type: Opaque
data:
db-password: {{ .Values.secret.dbPassword }}
EOF
cat > helm/node-webapp/templates/deployment.yaml << 'EOF'
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ .Release.Name }}
labels:
app: {{ .Release.Name }}
spec:
replicas: {{ .Values.replicaCount }}
selector:
matchLabels:
app: {{ .Release.Name }}
template:
metadata:
labels:
app: {{ .Release.Name }}
spec:
containers:
- name: node-webapp
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
ports:
- containerPort: {{ .Values.service.targetPort }}
envFrom:
- configMapRef:
name: {{ .Release.Name }}-config
env:
- name: DB_PASSWORD
valueFrom:
secretKeyRef:
name: {{ .Release.Name }}-secret
key: db-password
resources:
{{- toYaml .Values.resources | nindent 10 }}
EOF
cat > helm/node-webapp/templates/service.yaml << 'EOF'
apiVersion: v1
kind: Service
metadata:
name: {{ .Release.Name }}-svc
spec:
type: {{ .Values.service.type }}
selector:
app: {{ .Release.Name }}
ports:
- port: {{ .Values.service.port }}
targetPort: {{ .Values.service.targetPort }}
EOF
Preview the rendered output
Before deploying, use helm template to see exactly what YAML Helm will generate:
helm template my-webapp helm/node-webapp
You'll see all 4 fully-rendered YAML files printed to the terminal with all {{ }} placeholders replaced by your values.
This is replaced by whatever name you give the release at install time. So if you run helm install prod-webapp ..., all your resources get prefixed with prod-webapp-. This lets you deploy the same chart multiple times (staging, prod) without name collisions.
Deploy & Manage with Helm
First delete the kubectl-deployed resources
We'll re-deploy the same app using Helm instead:
kubectl delete -f manifests/
Install with Helm
helm install my-webapp helm/node-webapp
# Expected output:
# NAME: my-webapp
# LAST DEPLOYED: ...
# NAMESPACE: default
# STATUS: deployed
# REVISION: 1
# Verify all resources were created kubectl get pods,svc,configmap,secret # List Helm releases helm list
Upgrade change replicas & image version
Bump to 5 replicas and update the image tag — no YAML editing needed:
helm upgrade my-webapp helm/node-webapp \ --set replicaCount=5 \ --set image.tag=2.0 # Watch pods rolling out kubectl get pods --watch
View release history
helm history my-webapp
# REVISION STATUS DESCRIPTION
# 1 superseded Install complete
# 2 deployed Upgrade complete
Rollback to revision 1
Something went wrong with version 2.0? Roll back instantly:
helm rollback my-webapp 1
# Kubernetes rolls Pods back to image:1.0 with 3 replicas
kubectl get pods --watch
Clean up
# Uninstall the release (removes ALL Kubernetes objects it created) helm uninstall my-webapp # Delete the cluster gcloud container clusters delete my-app-cluster \ --zone=us-central1-a
You just deployed, upgraded, rolled back, and uninstalled a real app using Helm with proper config management via ConfigMaps and Secrets. This is how apps are managed in real GKE environments.
Congratulations!
Intermediate GKE Complete!
You've graduated from hello-world commands to production-grade Kubernetes engineering.
What you accomplished
- Wrote real declarative YAML manifests for Deployment and Service
- Created a ConfigMap to inject non-sensitive app configuration
- Created a Secret to inject sensitive credentials securely
- Deployed a full app with
kubectl apply -f - Built a complete Helm chart with parameterized templates
- Deployed, upgraded, rolled back, and uninstalled using Helm
Your GKE progression
| Level | Skills | Status |
|---|---|---|
| Beginner | kubectl commands, Pods, Deployments, Services, scaling | ✅ Done |
| Intermediate | YAML manifests, ConfigMaps, Secrets, Helm charts | ✅ Done |
| Advanced | Ingress, HPA, Workload Identity, GitOps, Cloud Build CI/CD | ⏭ Up next |
What to learn next
| Topic | Why it matters | Where to learn |
|---|---|---|
| Horizontal Pod Autoscaler | Scale Pods automatically based on CPU/memory | kubernetes.io |
| GKE Ingress / Gateway API | Route traffic by domain, path, and TLS | GKE Docs |
| Workload Identity | Let Pods access GCP services without service account keys | GKE Docs |
| Cloud Build CI/CD | Auto-deploy on every Git push | Cloud Build Docs |
| Sealed Secrets | Safely store encrypted Secrets in Git | GitHub |