Cluster & Deployment

Create an Autopilot Cluster

Example

gcloud container clusters create-auto shop-cluster --region asia-south1
gcloud container clusters get-credentials shop-cluster --region asia-south1
kubectl get nodes

Example output

Creating cluster shop-cluster in asia-south1... Cluster is being health-checked (master is healthy)...done.
kubeconfig entry generated for shop-cluster.
NAME                                         STATUS   ROLES    AGE   VERSION
gk3-shop-cluster-pool-2-1a2b3c4d-x9k2         Ready    <none>   3m    v1.30.5-gke.1014001

Deploy and Expose an App

Example

A Deployment with 3 replicas and a Service of type LoadBalancer:

k8s.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: course-api
spec:
  replicas: 3
  selector:
    matchLabels: { app: course-api }
  template:
    metadata:
      labels: { app: course-api }
    spec:
      containers:
        - name: api
          image: asia-south1-docker.pkg.dev/shop-dev-1234/apps/course-api:1.2.0
          ports: [{ containerPort: 8080 }]
          resources:
            requests: { cpu: 250m, memory: 256Mi }
          readinessProbe:
            httpGet: { path: /health, port: 8080 }
---
apiVersion: v1
kind: Service
metadata:
  name: course-api
spec:
  type: LoadBalancer
  selector: { app: course-api }
  ports: [{ port: 80, targetPort: 8080 }]

Example (apply)

kubectl apply -f k8s.yaml
kubectl get service course-api

Example output

deployment.apps/course-api created
service/course-api created
NAME         TYPE           CLUSTER-IP     EXTERNAL-IP     PORT(S)        AGE
course-api   LoadBalancer   34.118.230.5   34.93.120.45    80:31234/TCP   62s