gcp cloud deploy getting started

To create a deployment pipeline in GCP, we create a skaffold.yaml which contains deployment profiles like dev, uat and prod. 

We use clouddeploy.yaml to wire actual deployment together 

In this example, we are deploying to service which is basically cloud run (azure function in Azure)

skaffold.yaml



apiVersion: skaffold/v4beta7
kind: Config
metadata:
  name: deploy-run-quickstart
profiles:
- name: dev
  manifests:
    rawYaml:
    - run-service-dev.yaml
- name: prod
  manifests:
    rawYaml:
    - run-service-prod.yaml
deploy:
  cloudrun: {}


run-service-dev.yaml


apiVersion: serving.knative.dev/v1
kind: Service
metadata:
  name: deploy-run-service-dev
spec:
  template:
    spec:
      containers:
      - image: my-app-image

run-service-prod.yaml


apiVersion: serving.knative.dev/v1
kind: Service
metadata:
  name: deploy-run-service-prod
spec:
  template:
    spec:
      containers:
      - image: my-app-image


Creating our pipeline

And finally we have clouddeploy.yaml which is the actual deployment pipeline that define stages from dev to prod. 


apiVersion: deploy.cloud.google.com/v1
kind: DeliveryPipeline
metadata:
  name: my-run-demo-app-1
description: main application pipeline
serialPipeline:
  stages:
  - targetId: run-qsdev
    profiles: [dev]
  - targetId: run-qsprod
    profiles: [prod]
---

apiVersion: deploy.cloud.google.com/v1
kind: Target
metadata:
  name: run-qsdev
description: Cloud Run development service
run:
  location: projects/project-xxxxx/locations/us-central1
---

apiVersion: deploy.cloud.google.com/v1
kind: Target
metadata:
  name: run-qsprod
description: Cloud Run production service
run:
  location: projects/project-xxxxx/locations/us-central1


Run the following command to create this pipeline 



gcloud deploy apply --file=clouddeploy.yaml
--region=us-central1 --project=project-xxxxx

And this is what it looks like :- 



And then we can trigger our pipeline to run - start release to deploy and create a cloud run 



 gcloud deploy releases create test-release-001
--project=project-xxxx  --region=us-central1
--delivery-pipeline=my-run-demo-app-1
--images=my-app-image=us-docker.pkg.dev/cloudrun/container/hello@sha256:95ade4b17adcd07623b0a0c68359e344fe54e65d0cb01b989e24c39f2fcd296a





Setting up cloud run settings

In our previous configuration file, we don't have much settings. Let's say we would like to configure the memory and environment variables - how can we do that? In that case, we can tweak out yaml file here

apiVersion: serving.knative.dev/v1
kind: Service
metadata:
  name: deploy-run-service-dev
spec:
  template:
    spec:
      containers:
      - image: my-app-image
        resources:
            limits:
              memory: 712Mi
              cpu: "1"
        env:
          - name: ENV
            value: dev
          - name: KV
            value: demo
       


And then, after we create another release, it will be reflected in our cloud run :-




And other configurations of interest would be :-



apiVersion: serving.knative.dev/v1
kind: Service
metadata:
  name: deploy-run-service-dev
  annotations:
    run.googleapis.com/ssh-enabled: "true"      # enables SSH on the service
    run.googleapis.com/launch-stage: BETA       # SSH is a Preview feature
spec:
  template:
    # scaling to max 4 instances
    template:
    metadata:
      annotations:
        run.googleapis.com/execution-environment: gen2   # SSH requires gen2
        autoscaling.knative.dev/minScale: "1" # setting up min scale
        autoscaling.knative.dev/maxScale: "4" # setting up max scale
        run.googleapis.com/scaling-cpu-target: "0.4" # setting up cpu target
        run.googleapis.com/scaling-concurrency-target: "0.5" # setting up concurrency target
    spec:
      containers:
      - image: my-app-image
        resources:
            limits:
              memory: 712Mi
              cpu: "1"
       # setting up http2 for Cloud Run
        ports:
        - name: h2c
          containerPort: 8080
        env:
          - name: ENV
            value: dev
          - name: KV
            value: demo
       






Comments

Popular posts from this blog

NodeJS: Error: spawn EINVAL in window for node version 20.20 and 18.20

llama cpp running it in google colab