Skip to content

Lecture #08 - 11/03/2018

Agenda

  • Assignment #04 Review
  • Kubernetes Deployments
  • Continuous Integration, Continuous Delivery & Continuous Deployment
  • Assignment #05 Discussion

Slides

Info

To view slides, students must login to Office 365 with their Microsoft Student Advantage account. Office 365 (Microsoft Student Advantage) access details can be found here.

Reading

Demo Files & Commands

app.js

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
const http = require('http');
const os = require('os');

console.log("Server starting...");

var handler = function(request, response) {
  console.log("Received request from " + request.connection.remoteAddress);
  response.writeHead(200);
  //response.writeHead(500);
  //response.end("Something went wrong!!!! 500 Internal Server Error. You've hit " + os.hostname() + "\n");
  response.end("You've hit " + os.hostname() + " service v2\n");
};

var www = http.createServer(handler);
www.listen(8080);

Dockerfile

1
2
3
FROM node:7
ADD app.js /app.js
ENTRYPOINT ["node", "app.js"]

ReplicationController & Load Balancer Service

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
---
apiVersion: v1
kind: ReplicationController
metadata:
  name: csye7374-l8-rc-v1
spec:
  replicas: 3
  template:
    metadata:
      name: csye7374-l8
      labels:                      
        app: csye7374-l8                 
    spec:
      containers:
      - image: XXXXXXXXXX.dkr.ecr.us-east-1.amazonaws.com/csye7374:l8v1       
        name: csye7374            
        ports:
        - containerPort: 8080    
          protocol: TCP
---                                
apiVersion: v1
kind: Service
metadata:
  name: csye7374-l8-lb
spec:
  type: LoadBalancer
  selector:                        
    app: csye7374-l8                     
  ports:
  - port: 80
targetPort: 8080

Deployment Spec

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
apiVersion: apps/v1beta1          
kind: Deployment                  
metadata:
  name: csye7374-l8-deployment-v1                     
spec:
  replicas: 3
  minReadySeconds: 10
  strategy:
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 0
    type: RollingUpdate
  template:
    metadata:
      name: csye7374-l8
      labels:
        app: csye7374-l8
    spec:
      containers:
      - image: XXXXXXXXXX.dkr.ecr.us-east-1.amazonaws.com/csye7374:l8v3       
        name: csye7374            
        ports:
        - containerPort: 8080    
protocol: TCP

Commands

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# export VERSION=`date '+%Y.%m.%d.%H%M%S'`
# echo $VERSION

sudo `aws ecr get-login --no-include-email --region us-east-1`

sudo docker build -t csye7374 .

sudo docker tag csye7374 XXXXXXXXXX.dkr.ecr.us-east-1.amazonaws.com/csye7374:l8v1

sudo docker push XXXXXXXXXX.dkr.ecr.us-east-1.amazonaws.com/csye7374:l8v1

kubectl apply -f rc-svc-v1.yaml

while true; do curl http://ae9c20ccddf5a11e8b3e712299ce5dfb-1990465810.us-east-1.elb.amazonaws.com/ && sleep 1; done

sudo docker build -t csye7374 .

sudo docker tag csye7374 XXXXXXXXXX.dkr.ecr.us-east-1.amazonaws.com/csye7374:l8v2

sudo docker push XXXXXXXXXX.dkr.ecr.us-east-1.amazonaws.com/csye7374:l8v2

kubectl rolling-update csye7374-l8-rc-v1 csye7374-l8-rc-v3 --image=XXXXXXXXXX.dkr.ecr.us-east-1.amazonaws.com/csye7374:l8v2 --v 6

kubectl delete rc --all

sudo docker build -t csye7374 .

sudo docker tag csye7374 XXXXXXXXXX.dkr.ecr.us-east-1.amazonaws.com/csye7374:l8v3

sudo docker push XXXXXXXXXX.dkr.ecr.us-east-1.amazonaws.com/csye7374:l8v3

kubectl create -f deployment-v1.yaml --record

kubectl rollout status deployment csye7374-l8-deployment-v1

kubectl get po

kubectl get replicasets

while true; do curl http://ae9c20ccddf5a11e8b3e712299ce5dfb-1990465810.us-east-1.elb.amazonaws.com/ && sleep 1; done

kubectl set image deployment csye7374-l8-deployment-v1 csye7374=XXXXXXXXXX.dkr.ecr.us-east-1.amazonaws.com/csye7374:l8v3 

kubectl set image deployment csye7374-l8-deployment-v1 csye7374=XXXXXXXXXX.dkr.ecr.us-east-1.amazonaws.com/csye7374:l8v4 

kubectl rollout status deployment csye7374-l8-deployment-v1

kubectl rollout undo deployment csye7374-l8-deployment-v1

kubectl rollout history deployment csye7374-l8-deployment-v1

kubectl rollout undo deployment csye7374-l8-deployment-v1 --to-revision=1

kubectl rollout pause deployment csye7374-l8-deployment-v1

kubectl rollout resume deployment csye7374-l8-deployment-v1