Upgrade to Pro — share decks privately, control downloads, hide ads and more …

A Practical Guide to Cloud-Native Java Apps & C...

A Practical Guide to Cloud-Native Java Apps & Continuous Delivery

I've presented this deck at JavaOne 2016, where I showed how to get started with getting a simple Java app to run on Kubernetes in minutes, make changes on your workstation, and deploying it onto a Kubernetes cluster instantly. I then introduced concepts of continuous delivery, focusing on monitoring the app with Prometheus. Having shown a simple app, the presentation follows up with a complete microservices demo app, a sock shop that uses Spring as well as non-Java services (including Node.js and Go).

Ilya Dmitrichenko

October 02, 2017
Tweet

More Decks by Ilya Dmitrichenko

Other Decks in Technology

Transcript

  1. Microservices BoF Oct 2, 6:30 pm, room 2002 with Chris

    Richardson, Josh Long, & Ilya Dmitrichenko Kubernetes BoF Oct 2, 7:30 pm, room 2002 with Ilya Dmitrichenko & Tamao Nakahara
  2. apiVersion: v1 kind: Pod metadata: name: java-demo labels:{ app: java-demo

    } spec: containers: - name: server image: java-demo:v0.0.1 ports: [{ containerPort: 8080 }]
  3. apiVersion: v1 kind: Pod metadata: name: java-demo labels:{ app: java-demo

    } spec: containers: - name: server image: java-demo:v0.0.1 ports: [{ containerPort: 8080 }]
  4. apiVersion: v1 kind: Pod metadata: name: java-demo labels:{ app: java-demo

    } spec: containers: - name: server image: java-demo:v0.0.1 ports: [{ containerPort: 8080 }]
  5. apiVersion: v1 kind: Pod metadata: name: java-demo labels:{ app: java-demo

    } spec: containers: - name: server image: java-demo:v0.0.1 ports: [{ containerPort: 8080 }]
  6. apiVersion: apps/v1beta2 kind: Deployment metadata: name: java-demo labels:{ app: java-demo

    } spec: replicas: <ReplicaCount> selector:{ matchLabels: <PodLabels> } template: <PodSpec>
  7. ReplicaCount = 3 PodLabels = { app: java-demo } PodSpec

    = { metadata: { labels:{ app: java-demo } } spec: containers: - name: server image: java-demo:v0.0.1 ports: [{ containerPort: 8080 }] }
  8. apiVersion: apps/v1beta2 kind: Deployment metadata: name: java-demo labels:{ app: java-demo

    } spec: replicas: <ReplicaCount> selector:{ matchLabels: <PodLabels> } template: <PodSpec>
  9. apiVersion: apps/v1beta2 kind: Deployment metadata: name: java-demo labels:{ app: java-demo

    } spec: replicas: 3 selector:{ matchLabels: <PodLabels> } template: <PodSpec>
  10. apiVersion: apps/v1beta2 kind: Deployment metadata: name: java-demo labels:{ app: java-demo

    } spec: replicas: 3 selector:{ matchLabels:{ app: java-demo } } template: <PodSpec>
  11. apiVersion: apps/v1beta2 kind: Deployment metadata: name: java-demo labels:{ app: java-demo

    } spec: replicas: 3 selector:{ matchLabels:{ app: java-demo } } template: metadata: { labels:{ app: java-demo } } spec: containers: - name: server image: java-demo:v0.0.1 ports: [{ containerPort: 8080 }]
  12. apiVersion: apps/v1beta2 kind: Deployment metadata: name: java-demo labels:{ app: java-demo

    } spec: replicas: 3 selector:{ matchLabels:{ app: java-demo } } template: metadata: { labels:{ app: java-demo } } spec: containers: - name: server image: java-demo:v0.0.1 ports: [{ containerPort: 8080 }]
  13. apiVersion: apps/v1beta2 kind: Deployment metadata: name: java-demo labels:{ app: java-demo

    } spec: replicas: 3 selector:{ matchLabels:{ app: java-demo } } template: metadata: { labels:{ app: java-demo } } spec: containers: - name: server image: java-demo:v0.0.1 ports: [{ containerPort: 8080 }]
  14. apiVersion: apps/v1beta2 kind: Deployment metadata: name: java-demo labels:{ app: java-demo

    } spec: replicas: 3 selector:{ matchLabels:{ app: java-demo } } template: metadata: { labels:{ app: java-demo } } spec: containers: - name: server image: java-demo:v0.0.1 ports: [{ containerPort: 8080 }]
  15. apiVersion: apps/v1beta2 kind: Deployment metadata: name: java-demo labels:{ app: java-demo

    } spec: replicas: 3 selector:{ matchLabels:{ app: java-demo } } template: metadata: { labels:{ app: java-demo } } spec: containers: - name: server image: java-demo:v0.0.1 ports: [{ containerPort: 8080 }]
  16. apiVersion: apps/v1beta2 kind: Deployment metadata: name: java-demo labels:{ app: java-demo

    } spec: replicas: 3 selector:{ matchLabels:{ app: java-demo } } template: metadata: { labels:{ app: java-demo } } spec: containers: - name: server image: java-demo:v0.0.1 ports: [{ containerPort: 8080 }]
  17. apiVersion: apps/v1beta2 kind: Deployment metadata: name: java-demo labels:{ app: java-demo

    } spec: replicas: 3 selector:{ matchLabels:{ app: java-demo } } template: metadata: { labels:{ app: java-demo } } spec: containers: - name: server image: java-demo:v0.0.1 ports: [{ containerPort: 8080 }]
  18. > kubectl get deployment java-demo NAME DESIRED CURRENT UP-TO-DATE AVAILABLE

    AGE java-demo 3 3 3 3 1m > kubectl get pods -l app=java-demo NAME READY STATUS RESTARTS AGE java-demo-307071-c93l1 1/1 Running 0 1m java-demo-307071-f6nfc 1/1 Running 0 1m java-demo-307071-x4rr8 1/1 Running 0 1m
  19. apiVersion: v1 kind: Service metadata: name: java-demo labels:{ app: java-demo

    } spec: type: LoadBalancer selector:{ app: java-demo } ports: - name: http protocol: TCP port: 80 targetPort: 8080
  20. apiVersion: v1 kind: Service metadata: name: java-demo labels:{ app: java-demo

    } spec: type: LoadBalancer selector:{ app: java-demo } ports: - name: http protocol: TCP port: 80 targetPort: 8080
  21. apiVersion: v1 kind: Service metadata: name: java-demo labels:{ app: java-demo

    } spec: type: LoadBalancer selector:{ app: java-demo } ports: - name: http protocol: TCP port: 80 targetPort: 8080
  22. > kubectl describe service java-demo Name: java-demo Labels: app=java-demo Selector:

    app=java-demo Type: LoadBalancer IP: 10.39.245.50 LoadBalancer Ingress: 35.197.214.121 Port: http 80/TCP Endpoints: 10.36.1.79:8080,10.36.1.80:8080,10.36.1.81:8080 ... > curl http://35.197.214.121/ Hello, JavaOne '17!
  23. > kubectl get pods -l app=java-demo -o wide NAME READY

    STATUS IP ... java-demo-307071-c93l1 1/1 Running 10.36.1.80 java-demo-307071-f6nfc 1/1 Running 10.36.1.79 java-demo-307071-x4rr8 1/1 Running 10.36.1.81
  24. > curl http://35.197.214.121/prometheus ... # HELP process_starttime_seconds The starttime of

    the Java virtual machine # TYPE process_starttime_seconds gauge process_starttime_seconds 1.506735317456E9 # HELP process_uptime_seconds The uptime of the Java virtual machine # TYPE process_uptime_seconds gauge process_uptime_seconds 145236.015
  25. > curl http://35.197.214.121/prometheus ... # HELP http_requests_duration_seconds Timer of servlet

    request # TYPE http_requests_duration_seconds summary http_requests_duration_seconds_count{method="GET",status=" 200",uri="/"} 2.0 http_requests_duration_seconds_sum{method="GET",status="20 0",uri="/"} 0.05230485
  26. – gitops theory • any developer can use git •

    anyone can join team and ship a new app or make changes easily • all changes can be stored, audited and validated in git and we didn’t have to do anything very new or clever =)
  27. – gitops theory • config is code • code (&

    config!) must be version controlled • CD tools that do not record changes in git are harmful
  28. – gitops theory Continuous Delivery/Deployment Image Repo Orchestrator Deploy Synchronizer

    Config change Manual deployment Git Code change Git Update Hint Continuous Integration Deploy Automator CI Pipeline
  29. – more gitops •everything is checked in git •easy to

    deploy the entire stack locally •easy to fork a cluster •easy to detect ad-hoc changes, alert/undo
  30. – more gitops •git is the source of truth •review

    process is the same as for code •infra changes go through review process •you are free to use whatever tools
  31. tutorial part 1: deploying Spring Boot app to Kubernetes, step-by-step

    http://github.com/errordeveloper/prom-java-demo
  32. Microservices BoF Oct 2, 6:30 pm, room 2002 with Chris

    Richardson, Josh Long, & Ilya Dmitrichenko Kubernetes BoF Oct 2, 7:30 pm, room 2002 with Ilya Dmitrichenko & Tamao Nakahara