Skip to content

Instantly share code, notes, and snippets.

@0xAhmed
0xAhmed / set-image
Last active October 10, 2017 13:07
Set k8s image
$ kubectl --namespace=production set image deployment/kubeapp-production kubeapp=gcr.io/$PROJECT_ID/app:2.0
@0xAhmed
0xAhmed / get-version
Last active October 10, 2017 13:08
Request app version from k8s LB
$ for i in `seq 1 10`; do curl http://$SERVICE_IP/version; sleep 1; done
1.0
1.0
1.0
2.0
1.0
2.0
1.0
2.0
1.0
@0xAhmed
0xAhmed / apply-canary
Last active October 10, 2017 13:08
Applying a k8s canary Deployment
# Parse PROJECT_ID in k8s config
$ sed -i.bak "s#PROJECT_ID#$PROJECT_ID#" app-canary.yml
$ kubectl --namespace=production apply -f app-canary.yml
deployment "kubeapp-canary" created
$ kubectl --namespace=production get pods
NAME READY STATUS RESTARTS AGE
kubeapp-canary-469258524-2qjk0 1/1 Running 0 32s
kubeapp-production-1443420586-58njk 1/1 Running 0 1h
@0xAhmed
0xAhmed / app-canary.yml
Created October 3, 2017 13:23
Example k8s canary Deployment
kind: Deployment
apiVersion: extensions/v1beta1
metadata:
name: kubeapp-canary
spec:
replicas: 1
template:
metadata:
name: kubeapp
labels:
@0xAhmed
0xAhmed / build-and-push
Last active October 10, 2017 13:18
Build Docker image for 2.0 and push to GCR
$ export app_version=2.0
$ docker build --build-arg version=$app_version -t gcr.io/$PROJECT_ID/app:$app_version .
Sending build context to Docker daemon 16.48MB
Step 1/6 : FROM alpine:latest
---> 7328f6f8b418
Step 2/6 : MAINTAINER The Dockbit Team "team@dockbit.com"
---> Using cache
---> 6abecc069f97
Step 3/6 : ARG version=1.0
@0xAhmed
0xAhmed / k8s-lb-addr
Last active October 10, 2017 13:19
Get k8s Service IP Address
$ export SERVICE_IP=$(kubectl --namespace=production get service/app-lb --output=json | jq -r '.status.loadBalancer.ingress[0].ip')
$ curl http://$SERVICE_IP/
Congratulations! Version 1.0 of your application is running on Kubernetes.
$ curl http://$SERVICE_IP/version
1.0
@0xAhmed
0xAhmed / k8s-get-services
Last active October 10, 2017 13:20
Check k8s Services
$ kubectl --namespace=production get services
NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE
app-lb 10.63.250.99 35.196.71.189 80:32250/TCP 2m
@0xAhmed
0xAhmed / apply-lb
Last active October 10, 2017 13:48
Applying a k8s LB
$ kubectl --namespace=production apply -f app-lb.yml
service "app-lb" created
@0xAhmed
0xAhmed / app-lb.yml
Last active October 3, 2017 13:22
Example k8s LB as a Service
kind: Service
apiVersion: v1
metadata:
name: app-lb
spec:
type: LoadBalancer
ports:
- name: http
port: 80
targetPort: 8080
@0xAhmed
0xAhmed / k8s-get-pods
Last active October 10, 2017 13:20
Check k8s Pods
$ kubectl --namespace=production get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE
kubeapp-production-1979975788-8gkxn 1/1 Running 0 1m 10.60.2.7 gke-canary-default-pool-f3096f17-76ld
kubeapp-production-1979975788-m5v7r 1/1 Running 0 1m 10.60.0.9 gke-canary-default-pool-f3096f17-g4fc
kubeapp-production-1979975788-phhkw 1/1 Running 0 1m 10.60.1.7 gke-canary-default-pool-f3096f17-lxqs