Giter Site home page Giter Site logo

hutchison-technologies / gcloud-k8s-docker-shipper Goto Github PK

View Code? Open in Web Editor NEW
0.0 3.0 0.0 10 KB

A docker container to perform kubernetes based google cloud deployments

License: MIT License

k8s google-cloud kubectl deployment docker continuous-integration continuous-deployment automation automated

gcloud-k8s-docker-shipper's Introduction

Google Cloud + Kubernetes deployment

Docker Build Status

This docker file aims to help with automated deployment to Kubernetes running on the Google Cloud Platform. The image prepares a container ready to use gcloud and kubectl command line tools.

Usage

Using the example script in examples/deploy.sh. The environment variables used are completely dependent on what is going on inside the script.

docker run --rm \
  -v `pwd`/examples/:/examples \
  -e GOOGLE_SERVICE_ACCOUNT= \    # service account ID
  -e GOOGLE_SERVICE_KEY_BLOB= \   # base64 encoded JSON key of the service account
  -e PROJECT_ID= \                # google cloud project id
  -e COMPUTE_ZONE= \              # e.g.: europe-west3-a
  -e CLUSTER_NAME= \              # Name your cluster, e.g.: cluster1
  -e GOOGLE_SQL_KEY_BLOB= \       # base64 encoded JSON key of the service account with SQL API Client role
  -e DATABASE_USER= \             # Credentials required by your app
  -e DATABASE_PASSWORD= \         # Credentials required by your app
  -e DEPLOYMENT_NAME= \           # Name of your Kubernetes deployment config
  -e CONTAINER_NAME= \            # Name of the container in the deployment config
  -e NEW_IMAGE= \                 # New image to use for the specified container
  hutchisont/gcloud-k8s-docker-shipper \
  /examples/deploy.sh

Example deploy scripts

IMPORTANT: This script relies on existence of a kubernetes deployment configuration in the current directory.

#!/usr/bin/env bash

# Prepare gcloud auth credentials
echo -n -E $GOOGLE_SERVICE_KEY_BLOB | base64 --decode > /tmp/key.json

# Auth with gcloud using a service account and credentials file
gcloud auth activate-service-account $GOOGLE_SERVICE_ACCOUNT --key-file=/tmp/key.json

# Configure gcloud
gcloud config set project $PROJECT_ID
gcloud config set compute/zone $COMPUTE_ZONE

# Set up cluster
gcloud container clusters create $CLUSTER_NAME --enable-autoscaling --min-nodes=1 --max-nodes=10
gcloud container clusters get-credentials $CLUSTER_NAME

# If you're using a SQL instance, prepare SQL credentials for cloudsql proxy and create secrets to be used in deployment yaml
echo -n -E $GOOGLE_SQL_KEY_BLOB | base64 --decode > /tmp/sqlkey.json

# Recrate secrets if they already exist, otherwise the values will not be updated
secrets=`kubectl get secret`

if [[ $secrets =~ 'cloudsql-instance-credentials' ]]; then
  kubectl delete secret cloudsql-instance-credentials
fi
kubectl create secret generic cloudsql-instance-credentials --from-file=credentials.json=/tmp/sqlkey.json

if [[ $secrets =~ 'cloudsql-db-credentials' ]]; then
  kubectl delete secret cloudsql-db-credentials
fi
kubectl create secret generic cloudsql-db-credentials --from-literal=database_user=$DATABASE_USER --from-literal=database_password=$DATABASE_PASSWORD

# Apply yaml deployment configurations in the current directory
kubectl apply -f .

# Update an image of a deployed container
kubectl set image deployment/$DEPLOYMENT_NAME $CONTAINER_NAME=$NEW_IMAGE

gcloud-k8s-docker-shipper's People

Contributors

sashman avatar

Watchers

James Cloos avatar  avatar Liam Stupid Name Humphreys avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.