How to add Bash script to cloudbuild deployment, job?

version 1

steps:- name: 'bash'  args: ['echo', 'I am running a bash command']

version 2

steps:
- name: 'gcr.io/cloud-builders/gcloud'  
- entrypoint: 'bash'  
- args:  
 - '-eEuo'  
 - 'pipefail'  
 - '-c'  
 - |-
   if (( $(date '+%-e') % 2 )); then  
       echo "today is an odd day"
    else
       echo "today is an odd day, with an even number"
    fi
- name: another example
        image: gcr.io/ubuntu:latest
        command: ["/bin/sh"]
        args: 
        - '-c'
        - |
          DB_PATH="mysql://${MASTER_DSN}"
          echo "hello world!"
        imagePullPolicy: Always    
        env:
        - name: MASTER_DSN

Another example

steps:  
- name: 'gcr.io/cloud-builders/curl'  
entrypoint: 'bash'  
args:  
- '-c'  
- |  
  PET="$$(curl -s https://pets.doingdevops.com/pet_flaky --max-time 10)"  
  while [ "$$PET" == "ERROR" ] ; do  
      echo "Error: API failed to respond with a pet! Try again..."  
      PET="$$(curl -s https://pets.doingdevops.com/pet_flaky --max-time 10)"  
  done
    
  echo "Success! $${PET}"

References

Liveness vs Readiness Health Checks in Application

The liveness check finds if the application is alive or not. The application defines the logic and the liveness check verifies the expected output.
A webserver liveness check could include an HTTP handler that returns a fixed response or checks application dependencies.

Sample Liveness check

  • send a pong response in the handler
  • combine health check of all dependencies and return true/false

The Readiness check is to know if an application can accept traffic after initialization. A use case is a wait to serve traffic until all dependencies are ready. Essentially both checks have similar config options.

Sample Readiness Check

  • combine health check of all dependencies and return true/false
  • A init wait of 5 secs

References

Written with StackEdit.

Kubernetes: Adding A New Cluster Context

Visit the Google Cloud Console and navigate to clusters https://console.cloud.google.com/kubernetes/list

GCP Console
Here you will see all of your clusters.

Next, add a cluster to your kubectl context.

$ gcloud container clusters get-credentials --project my-project <cluster name> --region <cluster region>

Done!

Kubernetes for Dummies: StatefulSet

Kubernetes provides virtualized infrastructure components such as storage, compute and network. Imagine an operating system that allows users to allocate resources and run their applications.

StatefulSet is a type of application that needs to persist information across lifetimes 🙂

The storage is exposed as a class and name. Storage class mimic real world and has meta information such as size, type and provider of the storage. Kubernetes is following plugin based approcah like Linux kernel VFS :-). You can act as a provider of storage and define a class for such storage.

Storage type could be block or file. Like Linux, a file type storage gets a mountpoint.

The following snippet defines a storage class of type SSD, using Google’s storage. Retain means we keep the data even after the node (pod) is down.

  ---
  kind: StorageClass
  apiVersion: storage.k8s.io/v1
  metadata:
    name: my-storage-class
  provisioner: kubernetes.io/gce-pd
  reclaimPolicy: Retain
  parameters:
    type: pd-ssd
    replication-type: none
  ---

gce-pd means Google Cloud Engine- Persistent Disk.

The Kubernetes template for the instance would also specify how to use the storage with a PersistentVolumeClaim. The idea is that the instance first claims a persistent volume of a particular class. It also mentions access type and needed size.

volumeClaimTemplates:
  - metadata:
      name: a-new-claim
    spec:
      accessModes: [ "ReadWriteOnce" ]
      storageClassName: "my-storage-class"
      resources:
        requests:
          storage: 1Gi

ReadWriteOnce means that the volume is mounted once for read and write. It just menas a regular storage space.

Now just use the claim under containers section.

containers:
      - name: nginx
        image: k8s.gcr.io/nginx-slim:0.8
        volumeMounts:
        - name: a-new-claim
          mountPath: /usr/share/nginx/html

You will have a mounted path /usr/share/nginx/html in the container. Behavior is similar to local mount exported by NFS 🙂

REFERENCES

Written with StackEdit.