Skip to content

codeworks-secops/gcp-canary-deployment

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

1- Architecture

Link to the Architecture Diagram

2- Create new GCP Project

  • Get the billing accounts list

    gcloud alpha billing accounts list
  • Get the Organisation ID

    ORGANISATION_ID=$(gcloud organizations describe codeworks.fr --format=json | jq '.name' | cut -f 2 -d '/' | sed 's/"//g')
  • Name the project

    PROJECT_NAME=codeday-canary-deployment-demo
  • Create new project

    gcloud projects create ${PROJECT_NAME} --organization=${ORGANISATON_ID}
  • Get the project number

    PROJECT_NUMBER=$(gcloud projects describe $PROJECT_NAME --format='value(projectNumber)')
  • Link the project to the billing account

    gcloud alpha billing accounts projects link ${PROJECT_NUMBER} --account-id=0150EE-171E17-3E357F
  • Inspects

    • From your terminal

      gcloud projects list
    • From the Google Cloud Console

3- Init GCP configuration

  • Configure the gcloud tool to match account / project / zone to use from scratch
    gcloud init
  • Display zones list
    gcloud compute zones list
  • Another init !! to init the compute zone
    gcloud init
  • Checl all of the configuration
    gcloud config list

4- Google Container Registry

  • Build docker images

    • Stable version
    cd nodeapp/stable
    
    docker build -t gcr.io/${PROJECT_NAME}/nodeapp-stable:1.0.0 .
    • Canary version
    cd nodeapp/canary
    
    docker build -t gcr.io/${PROJECT_NAME}/nodeapp-canary:1.0.0 .
  • Launch the Docker image in your local host

    • Launch the stable image

      docker run --publish 9000:7070 --detach --name stable-app gcr.io/${PROJECT_NAME}/nodeapp-stable:1.0.0
    • Launch the canary image

      docker run --publish 9001:7070 --detach --name canary-app gcr.io/${PROJECT_NAME}/nodeapp-canary:1.0.0
    • Test containers using localhost

      Stable Version

      Canary Version

    • Test containers using internal IP address

      Stable Version

      Canary Version

  • Login :set up a credential helper

    gcloud auth configure-docker
  • Push all of images to the GCR

    • Stable version

      docker push gcr.io/${PROJECT_NAME}/nodeapp-stable:1.0.0
    • Canary version

      docker push gcr.io/${PROJECT_NAME}/nodeapp-canary:1.0.0

5- Create new cluster

gcloud container clusters create stable-canary-cluster --num-nodes=2

6- It's time to use Kubectl !

  • Create a new Namespace

    kubectl create ns stable-canary
  • Create Deployment Resource

    • Stable Application

      cat ./k8s/app-stable.deployment.yml | sh ./k8s/config.sh | kubectl create --save-config --record -f -
    • Canary Application

      cat ./k8s/app-canary.deployment.yml | sh ./k8s/config.sh | kubectl create --save-config --record -f -
  • Create Service Resource

    kubectl create -f ./k8s/app.service.yml -n stable-canary --save-config --record

7- Check Running Applications

  • Open a browser and pick the external service IP address and launch it

  • Using a shell script : update the script ./curl_loadbalancer_service.sh with the right external service IP address

    ./curl_loadbalancer_service.sh

8 - Scale Canary / Stable version : 50% / 50 %

  • Stable version

    update app-stable.deployment.yml => replicas: 2

    cat ./k8s/app-stable.deployment.yml | sh ./k8s/config.sh | kubectl apply --record -f -
  • Canary version

    update app-canary.deployment.yml => replicas: 2

    cat ./k8s/app-canary.deployment.yml | sh ./k8s/config.sh | kubectl apply --record -f -

9 - Scale down Stable version and route all traffic to the Canary version :0% / 100%

  • Stable version

    update app-stable.deployment.yml => replicas: 0

    cat ./k8s/app-stable.deployment.yml | sh ./k8s/config.sh | kubectl apply --record -f -
  • Canary version

    update app-canary.deployment.yml => replicas: 4

    cat ./k8s/app-canary.deployment.yml | sh ./k8s/config.sh | kubectl apply --record -f -

10- Deleting your GCP resources

  • Delete the Services

    kubectl delete service nodeapp-service -n stable-canary
  • Delete the Deloyments

    kubectl delete deployment stable -n stable-canary
    kubectl delete deployment canary -n stable-canary
  • Delete the Namespace

    kubectl delete ns stable-canary
  • Delete the Cluster

    gcloud container clusters delete stable-canary-cluster
  • Delete the specific images

    gcloud container images delete gcr.io/${PROJECT_NAME}/nodeapp-stable:1.0.0
    gcloud container images delete gcr.io/${PROJECT_NAME}/nodeapp-canary:1.0.0
  • Delete the GCP Project

    gcloud projects delete $PROJECT_NAME

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published