42
commit => #GitHub => #CircleCI => #Docker => #Kubernetes #AWS cluster 6. sraz přátel Symfony v Praze 31.3.2016

commit => #GitHub => #CircleCI => #Docker => #Kubernetes #AWS cluster

Embed Size (px)

Citation preview

Page 1: commit => #GitHub => #CircleCI => #Docker => #Kubernetes #AWS cluster

commit => #GitHub => #CircleCI => #Docker =>

#Kubernetes #AWS cluster6. sraz přátel Symfony v Praze

31.3.2016

Page 2: commit => #GitHub => #CircleCI => #Docker => #Kubernetes #AWS cluster

continuous integration … deployment

… delivery

Page 3: commit => #GitHub => #CircleCI => #Docker => #Kubernetes #AWS cluster

Kouzelná Almara

1 Java aplikace v Tomcatu (RESTful API + Wicket UI)

Page 4: commit => #GitHub => #CircleCI => #Docker => #Kubernetes #AWS cluster

Tomcat…?

hot deploy 🤘 PermGen 💩

Page 5: commit => #GitHub => #CircleCI => #Docker => #Kubernetes #AWS cluster

fuck it! 🐙

#BitBucket => #Bamboo => SSH upload WARka => jetty-runner.jar + automatický reload

po uploadu nového WARu (Node.JS skript)

Page 6: commit => #GitHub => #CircleCI => #Docker => #Kubernetes #AWS cluster

Skrz

3 frontend PHP(-FPM) aplikace, 2 3 ReactPHP aplikace, ~30 RabbitMQ consumers,

1 Go aplikace

Page 7: commit => #GitHub => #CircleCI => #Docker => #Kubernetes #AWS cluster

SVN 👹

Page 8: commit => #GitHub => #CircleCI => #Docker => #Kubernetes #AWS cluster

fuck it! 🐙

#BitBucket => BB hook => checkout git do ~/commits/<commit> => hook.sh => (na stagingu automaticky) swap.sh

Page 9: commit => #GitHub => #CircleCI => #Docker => #Kubernetes #AWS cluster

hitserver, adserver, ranking, RabbitMQ consumers

supervisord 🤘 porty 💩

Page 10: commit => #GitHub => #CircleCI => #Docker => #Kubernetes #AWS cluster

hitserver, adserver, ranking, RabbitMQ consumers

supervisord 💩 porty 💩

Page 11: commit => #GitHub => #CircleCI => #Docker => #Kubernetes #AWS cluster

Liftago

7 Java aplikací, 2 Node.JS aplikace, Python skripty v crontabu

Page 12: commit => #GitHub => #CircleCI => #Docker => #Kubernetes #AWS cluster

💩 Jelastic 💩 💩 Dogado 💩

Page 13: commit => #GitHub => #CircleCI => #Docker => #Kubernetes #AWS cluster

fuck! fuck fuck! 🐙

Page 14: commit => #GitHub => #CircleCI => #Docker => #Kubernetes #AWS cluster

❓ Java/PHP/Go/Node/… ❓ Java 7 vs. 8, PHP 5.3 vs. 7.0, … ❓ supervisor/autorestart ❓ rolling deployment ❓ porty ❓ nezávislé na hostingu

Page 15: commit => #GitHub => #CircleCI => #Docker => #Kubernetes #AWS cluster

❓ Java/PHP/Go/Node/… ✅ Docker ❓ Java 7 vs. 8, PHP 5.3 vs. 7.0, … ✅ Docker ❓ supervisor/autorestart ✅ Kubernetes ❓ rolling deployment ✅ Kubernetes ❓ porty ✅ Kubernetes ❓ nezávislé na providerovi ✅ Kubernetes

Page 16: commit => #GitHub => #CircleCI => #Docker => #Kubernetes #AWS cluster

Kubernetes

Page 17: commit => #GitHub => #CircleCI => #Docker => #Kubernetes #AWS cluster
Page 18: commit => #GitHub => #CircleCI => #Docker => #Kubernetes #AWS cluster
Page 19: commit => #GitHub => #CircleCI => #Docker => #Kubernetes #AWS cluster
Page 20: commit => #GitHub => #CircleCI => #Docker => #Kubernetes #AWS cluster

Pods

Docker container

billing:2016-03-31.345

Label app=billing

Label env=prod

Docker container

logrotate:latest

Volume

/var/lib/invoices

Volume

/var/log

10.0.0.348080

Page 21: commit => #GitHub => #CircleCI => #Docker => #Kubernetes #AWS cluster

Reconciliation loop

Observed state Desired state

Page 22: commit => #GitHub => #CircleCI => #Docker => #Kubernetes #AWS cluster

Reconciliation loop

Observed state Desired statecreate

Page 23: commit => #GitHub => #CircleCI => #Docker => #Kubernetes #AWS cluster

Reconciliation loop

Observed state Desired statescale

Page 24: commit => #GitHub => #CircleCI => #Docker => #Kubernetes #AWS cluster

Reconciliation loop

Observed state Desired statehealth check

Page 25: commit => #GitHub => #CircleCI => #Docker => #Kubernetes #AWS cluster

Replication controllerPod

billing 10.0.0.34Replication controller

billing-prod

app=billing env=prod replicas=3

app=billing

env=prod

Pod

billing 10.0.0.35

app=billing

env=prod

Pod

billing 10.0.0.36

app=billing

env=prod

Page 26: commit => #GitHub => #CircleCI => #Docker => #Kubernetes #AWS cluster

Replication controllerPod

billing 10.0.0.34Replication controller

billing-prod

app=billing env=prod

replicas=1

app=billing

env=prod

Page 27: commit => #GitHub => #CircleCI => #Docker => #Kubernetes #AWS cluster

Service

Pod

billing 10.0.0.34

Replication controller

billing-prod

app=billing

env=prodPod

billing 10.0.0.35

app=billing

env=prod

Pod

api 10.0.0.14

app=api

env=prod

??? ???

Page 28: commit => #GitHub => #CircleCI => #Docker => #Kubernetes #AWS cluster

Service

Pod

billing 10.0.0.34

Replication controller

billing-prod

app=billing

env=prod

Pod

api 10.0.0.14

app=api

env=prod

??? !!!

Page 29: commit => #GitHub => #CircleCI => #Docker => #Kubernetes #AWS cluster

Service

Pod

billing 10.0.0.34

Replication controller

billing-prod

app=billing

env=prodPod

billing 10.0.0.35

app=billing

env=prod

Pod

api 10.0.0.14

app=api

env=prod

Service billing-prod 10.1.0.1

Page 30: commit => #GitHub => #CircleCI => #Docker => #Kubernetes #AWS cluster

Service

Pod

billing 10.0.0.34

Replication controller

billing-prod

app=billing

env=prod

Pod

api 10.0.0.14

app=api

env=prod

Service billing-prod 10.1.0.1

Page 31: commit => #GitHub => #CircleCI => #Docker => #Kubernetes #AWS cluster

Service

Replication controller

billing-prod

Pod

billing 10.0.0.66

app=billing

env=prod

Pod

api 10.0.0.14

app=api

env=prod

Service billing-prod 10.1.0.1

Page 32: commit => #GitHub => #CircleCI => #Docker => #Kubernetes #AWS cluster

…a více• Job (cron scheduler plánovaný na 1.3)

• DaemonSet

• Horizontal Pod Autoscaler

• Secret

• Ingress

Page 33: commit => #GitHub => #CircleCI => #Docker => #Kubernetes #AWS cluster
Page 34: commit => #GitHub => #CircleCI => #Docker => #Kubernetes #AWS cluster

$ kubectl create -f - <<EOF > apiVersion: v1 > kind: ReplicationController > metadata: > name: billing-prod > spec: > replicas: 3 > template: > metadata: > labels: > app: billing > env: prod > spec: > containers: > - name: billing > image: docker-registry.liftago.com/billing:latest > imagePullPolicy: Always …

Page 35: commit => #GitHub => #CircleCI => #Docker => #Kubernetes #AWS cluster

… > env: > - name: SPRING_PROFILES_ACTIVE > value: prod > ports: > - containerPort: 8080 > livenessProbe: > httpGet: > path: /health > port: 8080 > initialDelaySeconds: 60 > timeoutSeconds: 5 > readinessProbe: > httpGet: > path: /health > port: 8080 > initialDelaySeconds: 1 > timeoutSeconds: 1 > imagePullSecrets: > - name: docker-repository.liftago.com > EOF

Page 36: commit => #GitHub => #CircleCI => #Docker => #Kubernetes #AWS cluster

$ kubectl create -f <<EOF > apiVersion: v1 > kind: Service > metadata: > name: billing-prod > labels: > app: billing > env: prod > spec: > clusterIP: 10.1.0.1 > ports: > - port: 80 > targetPort: 8080 > protocol: TCP > selector: > app: billing > env: prod > EOF

Page 37: commit => #GitHub => #CircleCI => #Docker => #Kubernetes #AWS cluster

$ kubectl get po -l app=billing,env=prod NAME READY STATUS RESTARTS AGE billing-prod-e3jcm 1/1 Running 0 1m billing-prod-4sdfb 1/1 Running 0 1m billing-prod-sd134 1/1 Running 0 1m

$ kubectl get rc -l app=billing,env=prod NAME DESIRED CURRENT AGE billing-prod 3 3 1m

$ kubectl get svc -l app=billing,env=prod NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE billing-prod 10.1.0.1 <none> 80/TCP 1m

Page 38: commit => #GitHub => #CircleCI => #Docker => #Kubernetes #AWS cluster

$ kubectl exec -it billing-prod-e3jcm bash $ cat /etc/hosts 127.0.0.1 billing-prod-e3jcm …

Page 39: commit => #GitHub => #CircleCI => #Docker => #Kubernetes #AWS cluster

kubernetes.io

github.com/jakubkulhan/kube-jessie-ansible github.com/jakubkulhan/dockerfiles

Page 40: commit => #GitHub => #CircleCI => #Docker => #Kubernetes #AWS cluster

A co ty commity/#GitHub/#CircleCI?

🤔

Page 41: commit => #GitHub => #CircleCI => #Docker => #Kubernetes #AWS cluster

machine: java: version: oraclejdk8 environment: DOCKER_TAG: $(date +%Y-%m-%d).$CIRCLE_BUILD_NUM services: - docker post: - docker login -e $DOCKER_EMAIL -u $DOCKER_USER -p $DOCKER_PASS $DOCKER_REGISTRY

dependencies: post: - sudo wget 'http://storage.googleapis.com/kubernetes-release/release/v1.2.0/bin/linux/amd64/kubectl' -O /usr/local/bin/kubectl - sudo chmod 755 /usr/local/bin/kubectl # docker pull suggested by https://discuss.circleci.com/t/caching-docker-image-with-docker-hub/1784 - docker pull $DOCKER_REGISTRY/$CIRCLE_PROJECT_REPONAME:latest || true

test: …

deployment: kubernetes: branch: master commands: - docker build -t $DOCKER_REGISTRY/$CIRCLE_PROJECT_REPONAME:$DOCKER_TAG . - docker push $DOCKER_REGISTRY/$CIRCLE_PROJECT_REPONAME:$DOCKER_TAG

- docker tag -f $DOCKER_REGISTRY/$CIRCLE_PROJECT_REPONAME:$DOCKER_TAG $DOCKER_REGISTRY/$CIRCLE_PROJECT_REPONAME:latest - docker push $DOCKER_REGISTRY/$CIRCLE_PROJECT_REPONAME:latest

- > kubectl config set-cluster kubernetes --server=$KUBERNETES_MASTER && kubectl config set-credentials circleci --token=$KUBERNETES_TOKEN && kubectl config set-context kubernetes --cluster=kubernetes --user=circleci && kubectl config use-context kubernetes

- kubectl rolling-update billing-prod --image=$DOCKER_REGISTRY/$CIRCLE_PROJECT_REPONAME:$DOCKER_TAG --update-period=10s

Page 42: commit => #GitHub => #CircleCI => #Docker => #Kubernetes #AWS cluster

Díky!Otázky?

twitter.com/jakubkulhan medium.com/@jakubkulhan

github.com/jakubkulhan