Skip to content

Instantly share code, notes, and snippets.

@nathanborror
Last active May 17, 2023 00:55
Show Gist options
  • Select an option

  • Save nathanborror/36ebcb42472775b1aa4a8edc135ee615 to your computer and use it in GitHub Desktop.

Select an option

Save nathanborror/36ebcb42472775b1aa4a8edc135ee615 to your computer and use it in GitHub Desktop.

Revisions

  1. nathanborror renamed this gist Jan 8, 2018. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. nathanborror renamed this gist Jan 8, 2018. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. nathanborror revised this gist Jan 8, 2018. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions kubernetes-config-map.yaml
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,7 @@ kind: ConfigMap
    metadata:
    name: example-config
    data:
    PODSTER_DB_HOST: postgres://postgres@postgres/example?sslmode=disable
    PODSTER_DB_KIND: postgres
    EXAMPLE_DB_HOST: postgres://postgres@postgres/example?sslmode=disable
    EXAMPLE_DB_KIND: postgres
    PGDATA: /var/lib/postgresql/data/pgdata
    POSTGRES_USER: postgres
  4. nathanborror revised this gist Jan 8, 2018. No changes.
  5. nathanborror created this gist Jan 8, 2018.
    9 changes: 9 additions & 0 deletions kubernetes-config-map.yaml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@
    apiVersion: v1
    kind: ConfigMap
    metadata:
    name: example-config
    data:
    PODSTER_DB_HOST: postgres://postgres@postgres/example?sslmode=disable
    PODSTER_DB_KIND: postgres
    PGDATA: /var/lib/postgresql/data/pgdata
    POSTGRES_USER: postgres
    151 changes: 151 additions & 0 deletions kubernetes.yaml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,151 @@
    apiVersion: extensions/v1beta1
    kind: Ingress
    metadata:
    name: example-ingress
    annotations:
    kubernetes.io/ingress.class: "gce"
    kubernetes.io/ingress.global-static-ip-name: example-ingress-ip
    spec:
    backend:
    serviceName: example-site
    servicePort: 8080
    rules:
    - http:
    paths:
    - path: /graphql
    backend:
    serviceName: example-api-svc
    servicePort: 8080
    - path: /*
    backend:
    serviceName: example-site-svc
    servicePort: 8080
    ---
    apiVersion: v1
    kind: Service
    metadata:
    name: postgres
    spec:
    ports:
    - port: 5432
    selector:
    app: postgres
    ---
    apiVersion: extensions/v1beta1
    kind: Deployment
    metadata:
    name: postgres
    spec:
    template:
    metadata:
    labels:
    app: postgres
    spec:
    containers:
    - image: "postgres:10.1"
    name: postgres
    envFrom:
    - configMapRef:
    name: example-config
    ports:
    - containerPort: 5432
    name: postgres
    volumeMounts:
    - name: postgres-storage
    mountPath: /var/lib/postgresql/data
    volumes:
    - name: postgres-storage
    gcePersistentDisk:
    fsType: ext4
    pdName: postgres-disk
    ---
    apiVersion: v1
    kind: Service
    metadata:
    name: example-api-svc
    labels:
    app: example-api
    spec:
    type: NodePort
    ports:
    - port: 8080
    nodePort: 30050
    selector:
    app: example-api
    ---
    apiVersion: extensions/v1beta1
    kind: Deployment
    metadata:
    name: example-api
    spec:
    replicas: 1
    template:
    metadata:
    labels:
    app: example-api
    spec:
    containers:
    - name: example-api
    image: gcr.io/YOUR_PROJECT_ID/example:b8886066cfa761cf858ce526b71513abbe1ac7c0
    command: ["/example", "serve", "--schema=schema.graphql"]
    envFrom:
    - configMapRef:
    name: example-config
    ports:
    - containerPort: 8080
    ---
    apiVersion: v1
    kind: Service
    metadata:
    name: example-site-svc
    labels:
    app: example-site
    spec:
    type: NodePort
    ports:
    - port: 8080
    nodePort: 30051
    selector:
    app: example-site
    ---
    apiVersion: extensions/v1beta1
    kind: Deployment
    metadata:
    name: example-site
    spec:
    replicas: 1
    template:
    metadata:
    labels:
    app: example-site
    spec:
    containers:
    - name: example-site
    image: gcr.io/YOUR_PROJECT_ID/example:b8886066cfa761cf858ce526b71513abbe1ac7c0
    command: ["/example", "site"]
    envFrom:
    - configMapRef:
    name: example-config
    ports:
    - containerPort: 8080
    ---
    apiVersion: batch/v1beta1
    kind: CronJob
    metadata:
    name: crawler
    spec:
    schedule: "@hourly"
    successfulJobsHistoryLimit: 0
    jobTemplate:
    spec:
    template:
    spec:
    containers:
    - name: crawler
    image: gcr.io/YOUR_PROJECT_ID/example:b8886066cfa761cf858ce526b71513abbe1ac7c0
    command: ["/example", "crawl"]
    envFrom:
    - configMapRef:
    name: example-config
    restartPolicy: Never
    ---
    46 changes: 46 additions & 0 deletions setup.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,46 @@
    *** Cluster Setup for Google Container Engine ***

    0/ Install and configure local gcloud and kubectl: https://cloud.google.com/sdk/docs/
    > gcloud components install kubectl

    1/ Configure Google Cloud account:
    > gcloud config set account YOUR_EMAIL_ADDRESS
    > gcloud config set project YOUR_PROJECT_ID
    > gcloud config set compute/zone us-west1-a
    > gcloud config set container/cluster example
    > gcloud container clusters get-credentials example

    2/ Create cluster on Google Cloud Console:
    > gcloud container clusters create example --machine-type=f1-micro --num-nodes=3 --scopes=cloud-platform --zone=us-west1-a

    3/ Create a static IP for Ingress:
    > gcloud compute addresses create example-ingress-ip --global

    4/ Create persistant disk for database:
    > gcloud compute disks create --size 200GB example-disk

    5/ Create configmap:
    > kubectl create configmap example-config -f kubernetes-config-map.yaml

    6/ Create deployments:
    > kubectl create -f kubernetes.yaml

    7/ Create database:
    > kubectl get pods
    > kubectl exec postgres-POD_IDENTIFIER --stdin --tty -- createdb -U postgres example

    ---

    98/ Destroy cluster:
    > kubectl delete -f kubernetes-config-map.yaml
    > kubectl delete -f kubernetes.yaml
    > gcloud container clusters delete example
    > gcloud compute disks delete example-disk
    > gcloud compute addresses delete example-ingress-ip

    99/ Web UI
    > gcloud container clusters get-credentials example --zone us-west1-a --project example
    > kubectl proxy
    > open http://localhost:8001/ui

    ---