Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save cullylarson/ad887809d72eb93f80eae73f84b5789c to your computer and use it in GitHub Desktop.
Save cullylarson/ad887809d72eb93f80eae73f84b5789c to your computer and use it in GitHub Desktop.

Convenient k8s/Docker/gcloud Commands

Commands that are useful for doing stuff on Google Container Engine

Setup

$ gcloud config set project PROJECT_ID
$ gcloud config set compute/zone ZONE_NAME
$ gcloud container clusters list
$ gcloud container clusters get-credentials CLUSTER_NAME

Docker

  • Build container

    $ docker build -t gcr.io/PROJECT_ID/APP_NAME:APP_VERSION
    
  • Push container to Google image registry

    $ gcloud docker push gcr.io/PROJECT_ID/APP_NAME:APP_VERSION
    

Container Engine

  • Deployment config file (e.g. deployment.yaml)

    apiVersion: extensions/v1beta1
    kind: Deployment
    metadata:
      name: DEPLOYMENT_NAME
    spec:
      replicas: 2
      template:
        metadata:
          labels:
            app: APP_NAME
        spec:
          containers:
          - name: APP_NAME
            image:  gcr.io/PROJECT_ID/APP_NAME:APP_VERSION
            ports:
            - containerPort: CONTAINER_PORT
    
  • Create the deployment

    $ kubectl create -f deployment.yaml
    
  • Service config file

    apiVersion: v1
    kind: Service
    metadata:
      name: SERVICE_NAME
    spec:
      type: LoadBalancer
      ports:
      - port: 80
        targetPort: 3000
      selector:
        app: APP_NAME
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment