Skip to content

Latest commit

 

History

History
311 lines (229 loc) · 6.58 KB

File metadata and controls

311 lines (229 loc) · 6.58 KB

GSP114 - Continuous Delivery Pipelines with Spinnaker and Kubernetes Engine

Task 1. Set up your environment

  1. Set zone

    gcloud config set compute/zone us-east1-d
  2. Buat cluster

    gcloud container clusters create spinnaker-tutorial \
    --machine-type=n1-standard-2
  3. Bust service account

    gcloud iam service-accounts create spinnaker-account \
    --display-name spinnaker-account
  4. Set env variable

    export SA_EMAIL=$(gcloud iam service-accounts list \
    --filter="displayName:spinnaker-account" \
    --format='value(email)')
    export PROJECT=$(gcloud info --format='value(config.project)')
  5. Bind storage.admin ke service account yang dibuat

    gcloud projects add-iam-policy-binding $PROJECT \
    --role roles/storage.admin \
    --member serviceAccount:$SA_EMAIL
  6. Download spinnaker key

    gcloud iam service-accounts keys create spinnaker-sa.json \
     --iam-account $SA_EMAIL

Task 2. Set up Cloud Pub/Sub to trigger Spinnaker pipelines

  1. Buat pub.sub

    gcloud iam service-accounts keys create spinnaker-sa.json \
     --iam-account $SA_EMAIL
  2. Buat subscription

    gcloud pubsub subscriptions create gcr-triggers \
    --topic projects/${PROJECT}/topics/gcr
  3. Kasih spinnaker account permission untuk read

    export SA_EMAIL=$(gcloud iam service-accounts list \
    --filter="displayName:spinnaker-account" \
    --format='value(email)')
    
    gcloud beta pubsub subscriptions add-iam-policy-binding gcr-triggers \
    --role roles/pubsub.subscriber --member serviceAccount:$SA_EMAIL

Task 3. Deploying Spinnaker using Helm

  1. Grant helm ke cluster-admin

    kubectl create clusterrolebinding user-admin-binding \
    --clusterrole=cluster-admin --user=$(gcloud config get-value account)
  2. Kasih juga ke spinnaker

    kubectl create clusterrolebinding --clusterrole=cluster-admin \
    --serviceaccount=default:default spinnaker-admin
  3. Add stable chart ke Helm

    helm repo add stable https://charts.helm.sh/stable
    helm repo update
  4. Buat bucket untuk spinnaker simpan conf nyua

    export PROJECT=$(gcloud info \
        --format='value(config.project)')
    export BUCKET=$PROJECT-spinnaker-config
    gsutil mb -c regional -l us-east1 gs://$BUCKET
  5. Buat spinnaker config

    export SA_JSON=$(cat spinnaker-sa.json)
    export PROJECT=$(gcloud info --format='value(config.project)')
    export BUCKET=$PROJECT-spinnaker-config
    cat > spinnaker-config.yaml <<EOF
    gcs:
    enabled: true
    bucket: $BUCKET
    project: $PROJECT
    jsonKey: '$SA_JSON'
    dockerRegistries:
    - name: gcr
    address: https://gcr.io
    username: _json_key
    password: '$SA_JSON'
    email: 1234@5678.com
    # Disable minio as the default storage backend
    minio:
    enabled: false
    # Configure Spinnaker to enable GCP services
    halyard:
    spinnakerVersion: 1.19.4
    image:
        repository: us-docker.pkg.dev/spinnaker-community/docker/halyard
        tag: 1.32.0
        pullSecrets: []
    additionalScripts:
        create: true
        data:
        enable_gcs_artifacts.sh: |-
            \$HAL_COMMAND config artifact gcs account add gcs-$PROJECT --json-path /opt/gcs/key.json
            \$HAL_COMMAND config artifact gcs enable
        enable_pubsub_triggers.sh: |-
            \$HAL_COMMAND config pubsub google enable
            \$HAL_COMMAND config pubsub google subscription add gcr-triggers \
            --subscription-name gcr-triggers \
            --json-path /opt/gcs/key.json \
            --project $PROJECT \
            --message-format GCR
    EOF
  6. Deploy spinnaker

    helm install -n default cd stable/spinnaker -f spinnaker-config.yaml \
           --version 2.0.0-rc9 --timeout 10m0s --wait
  7. Setup port forwarding

    export DECK_POD=$(kubectl get pods --namespace default -l "cluster=spin-deck" \
    -o jsonpath="{.items[0].metadata.name}")
    kubectl port-forward --namespace default $DECK_POD 8080:9000 >> /dev/null &

Task 4. Building the Docker image

  1. Download sample app

    gsutil -m cp -r gs://spls/gsp114/sample-app.tar .
  2. Unpack app

    mkdir sample-app
    tar xvf sample-app.tar -C ./sample-app
    cd sample-app
  3. Set username dan email git

    git config --global user.email "$(gcloud config get-value core/account)"
    git config --global user.name "[USERNAME]"
  4. Buat repo

    gcloud source repos create sample-app
  5. Tambah remote

    export PROJECT=$(gcloud info --format='value(config.project)')
    git remote add origin https://source.developers.google.com/p/$PROJECT/r/sample-app
  6. Push

    git push origin master

Prepare your Kubernetes Manifests for use in Spinnaker

  1. Buat bucket

    export PROJECT=$(gcloud info --format='value(config.project)')
    gsutil mb -l us-east1 gs://$PROJECT-kubernetes-manifests
  2. Enable versioning

    gsutil versioning set on gs://$PROJECT-kubernetes-manifests
  3. Set project id

    sed -i s/PROJECT/$PROJECT/g k8s/deployments/*
    
  4. Commit

    git commit -a -m "Set project ID"

Build imge

  1. But git tag

    git tag v1.0.0
  2. Push tag

    git push --tags

Task 5. Configuring your deployment pipelines

  1. Downlod spin

    curl -LO https://storage.googleapis.com/spinnaker-artifacts/spin/1.14.0/linux/amd64/spin
  2. Mke spin executable

    chmod +x spin
  3. But pipeline

    ./spin application save --application-name sample \
                        --owner-email "$(gcloud config get-value core/account)" \
                        --cloud-providers kubernetes \
                        --gate-endpoint http://localhost:8080/gate
  4. Uplod pipeline

    export PROJECT=$(gcloud info --format='value(config.project)')
    sed s/PROJECT/$PROJECT/g spinnaker/pipeline-deploy.json > pipeline.json
    ./spin pipeline save --gate-endpoint http://localhost:8080/gate -f pipeline.json

Task 6. Triggering your pipeline from code changes

  1. Ganti warn web

    sed -i 's/orange/blue/g' cmd/gke-info/common-service.go
  2. Commit n push

    git commit -a -m "Change color to blue"
    git tag v1.0.1
    git push --tags

Task 7. Observe the canary deployments

  1. Rollout

    git revert v1.0.1
    git tag v1.0.2
    git push --tags