Deploying Spring Boot Apps on Kubernetes Thomas Risberg, Pivotal @trisberg 1
Unless otherwise indicated, these slides are © 2013 -2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ Two Hot Technologies 2 https://trends.google.com/trends/explore?q=kubernetes,spring%20boot
Unless otherwise indicated, these slides are © 2013 -2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ About Me Thomas Risberg (@trisberg) • Member of the Spring engineering team at Pivotal • Contributing to Project riff and Spring Cloud Data Flow • Joined the Spring Framework open source project in 2003 working on JDBC support 3
Unless otherwise indicated, these slides are © 2013 -2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ Pair programming with Spring Team 4
Unless otherwise indicated, these slides are © 2013 -2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ Pairing with Google Engineering Team? 5 Kubernetes builds upon 15 years of experience of running production workloads at Google, combined with best- of-breed ideas and practices from the community. https://kubernetes.io/
Unless otherwise indicated, these slides are © 2013 -2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ Kubernetes Architecture 6 API Server Controller Manager Scheduler etcd Node Kubelet Pod Kube- proxy Pod Node Kubelet Kube- proxy Pod Pod
Unless otherwise indicated, these slides are © 2013 -2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ Deployment ReplicaSet Kubernetes Resources 7 Pod Docker hello.jar Service NodePort/LoadBalancer ConfigMap/Secret spring.datasource.username=test
Demo Simple Hello Spring Boot/Kubernetes app deployment https://github.com/trisberg/s1p2017-boot-k8s/blob/master/demo-hello.adoc
Unless otherwise indicated, these slides are © 2013 -2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ Building Apps for Kubernetes 9 https://twitter.com/kelseyhightower/status/903640408613306369
Unless otherwise indicated, these slides are © 2013 -2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ Contracts exposed to the apps by the platform 10 https://twitter.com/kelseyhightower/status/903643916599046145
Unless otherwise indicated, these slides are © 2013 -2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ Externalized Configuration •Environment variables •Easy to set in deployment.yaml •Might need to use SPRING_APPLICATION_JSON for map based properties •ConfigMaps and Secrets •Can be set using environment or mounted as config files •Use Spring Cloud Config Server •Init container can write properties file to shared volume 11
Demo Simple REST Repository App as part of a Microservice Architecture https://github.com/trisberg/s1p2017-boot-k8s/blob/master/demo-actors.adoc https://github.com/trisberg/s1p2017-boot-k8s/blob/master/demo-microservices.adoc https://github.com/trisberg/boot-k8s-microservices/tree/s1p2017
Unless otherwise indicated, these slides are © 2013 -2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ Mount ConfigMaps 13 apiVersion: v1 kind: ConfigMap metadata: name: actors labels: app: actors data: application.yaml: |- security: basic: enabled: false spring: datasource: url: jdbc:mysql://${MYSQL_SERVICE_HOST}:${MYSQL_SERVICE_PORT}/mysql username: root password: ${MYSQL_ROOT_PASSWORD} driverClassName: com.mysql.jdbc.Driver testOnBorrow: true validationQuery: "SELECT 1" spec: containers: - name: actors image: trisberg/actors:0.0.1-SNAPSHOT … volumeMounts: - name: application-config mountPath: "/config" readOnly: true volumes: - name: application-config configMap: name: actors items: - key: application.yaml path: application-kubernetes.yaml
Unless otherwise indicated, these slides are © 2013 -2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ Access Secrets in Env Var 14 env: - name: SERVER_PORT value: '80' - name: SPRING_PROFILES_ACTIVE value: kubernetes - name: MYSQL_ROOT_PASSWORD valueFrom: secretKeyRef: name: mysql key: mysql-root-password apiVersion: v1 kind: Secret metadata: name: mysql labels: app: mysql data: mysql-root-password: eW91cnBhc3N3b3Jk
Unless otherwise indicated, these slides are © 2013 -2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ Microservice Architecture Concerns 15 • Externalized Configuration • ConfigMap and Secrets • Service Discovery • DNS, DiscoveryClient • Circuit-breaker • Distributed Tracing • Metrics • Log aggregation
Unless otherwise indicated, these slides are © 2013 -2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ Microservice Runtime Management 16 •Circuit-breaker - Netflix Hystrix •Distributed Tracing - Spring Cloud Sleuth / Zipkin •Metrics - Spring Boot Actuator /Micrometer •Service Mesh - Istio •load balancing / routing •policy enforcement •telemetry and reporting
Unless otherwise indicated, these slides are © 2013 -2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ Log Aggregation 17 • Spring Cloud Sleuth ‣ https://cloud.spring.io/spring-cloud-sleuth/ • Stackdriver ‣ https://kubernetes.io/docs/tasks/debug-application-cluster/logging-stackdriver/ • Elasticsearch and Kibana ‣ https://kubernetes.io/docs/tasks/debug-application-cluster/logging-elasticsearch- kibana/ • Loggly ‣ https://www.weave.works/blog/log-aggregation-kubernetes-loggly/
Unless otherwise indicated, these slides are © 2013 -2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ Packaging 18 • Helm • The package manager for Kubernetes ‣https://docs.helm.sh/using_helm/#quickstart-guide • KubeApps • Discover & launch great Kubernetes-ready apps ‣https://kubeapps.com/ • Example ‣https://github.com/trisberg/boot-k8s-microservices/tree/s1p2017
Unless otherwise indicated, these slides are © 2013 -2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ Spring Cloud for Kubernetes 19 • Fabric8 team created spring-cloud-kubernetes • DiscoveryClient for Kubernetes • ConfigMap and Secrets PropertySource • Ribbon discovery in Kubernetes • Zipkin discovery in Kubernetes • and more … • Now available in spring-cloud-incubator on GitHub • Could join the Spring Cloud Release train for Greenwich sometime next year
Learn More. Stay Connected. Kubernetes for the Spring Developer - Wednesday 03:20 Room: 2024 https://github.com/spring-cloud-incubator/spring-cloud-kubernetes 20 #springone@s1p

Deploying Spring Boot apps on Kubernetes

  • 1.
    Deploying Spring BootApps on Kubernetes Thomas Risberg, Pivotal @trisberg 1
  • 2.
    Unless otherwise indicated,these slides are © 2013 -2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ Two Hot Technologies 2 https://trends.google.com/trends/explore?q=kubernetes,spring%20boot
  • 3.
    Unless otherwise indicated,these slides are © 2013 -2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ About Me Thomas Risberg (@trisberg) • Member of the Spring engineering team at Pivotal • Contributing to Project riff and Spring Cloud Data Flow • Joined the Spring Framework open source project in 2003 working on JDBC support 3
  • 4.
    Unless otherwise indicated,these slides are © 2013 -2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ Pair programming with Spring Team 4
  • 5.
    Unless otherwise indicated,these slides are © 2013 -2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ Pairing with Google Engineering Team? 5 Kubernetes builds upon 15 years of experience of running production workloads at Google, combined with best- of-breed ideas and practices from the community. https://kubernetes.io/
  • 6.
    Unless otherwise indicated,these slides are © 2013 -2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ Kubernetes Architecture 6 API Server Controller Manager Scheduler etcd Node Kubelet Pod Kube- proxy Pod Node Kubelet Kube- proxy Pod Pod
  • 7.
    Unless otherwise indicated,these slides are © 2013 -2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ Deployment ReplicaSet Kubernetes Resources 7 Pod Docker hello.jar Service NodePort/LoadBalancer ConfigMap/Secret spring.datasource.username=test
  • 8.
    Demo Simple Hello Spring Boot/Kubernetes appdeployment https://github.com/trisberg/s1p2017-boot-k8s/blob/master/demo-hello.adoc
  • 9.
    Unless otherwise indicated,these slides are © 2013 -2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ Building Apps for Kubernetes 9 https://twitter.com/kelseyhightower/status/903640408613306369
  • 10.
    Unless otherwise indicated,these slides are © 2013 -2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ Contracts exposed to the apps by the platform 10 https://twitter.com/kelseyhightower/status/903643916599046145
  • 11.
    Unless otherwise indicated,these slides are © 2013 -2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ Externalized Configuration •Environment variables •Easy to set in deployment.yaml •Might need to use SPRING_APPLICATION_JSON for map based properties •ConfigMaps and Secrets •Can be set using environment or mounted as config files •Use Spring Cloud Config Server •Init container can write properties file to shared volume 11
  • 12.
    Demo Simple REST RepositoryApp as part of a Microservice Architecture https://github.com/trisberg/s1p2017-boot-k8s/blob/master/demo-actors.adoc https://github.com/trisberg/s1p2017-boot-k8s/blob/master/demo-microservices.adoc https://github.com/trisberg/boot-k8s-microservices/tree/s1p2017
  • 13.
    Unless otherwise indicated,these slides are © 2013 -2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ Mount ConfigMaps 13 apiVersion: v1 kind: ConfigMap metadata: name: actors labels: app: actors data: application.yaml: |- security: basic: enabled: false spring: datasource: url: jdbc:mysql://${MYSQL_SERVICE_HOST}:${MYSQL_SERVICE_PORT}/mysql username: root password: ${MYSQL_ROOT_PASSWORD} driverClassName: com.mysql.jdbc.Driver testOnBorrow: true validationQuery: "SELECT 1" spec: containers: - name: actors image: trisberg/actors:0.0.1-SNAPSHOT … volumeMounts: - name: application-config mountPath: "/config" readOnly: true volumes: - name: application-config configMap: name: actors items: - key: application.yaml path: application-kubernetes.yaml
  • 14.
    Unless otherwise indicated,these slides are © 2013 -2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ Access Secrets in Env Var 14 env: - name: SERVER_PORT value: '80' - name: SPRING_PROFILES_ACTIVE value: kubernetes - name: MYSQL_ROOT_PASSWORD valueFrom: secretKeyRef: name: mysql key: mysql-root-password apiVersion: v1 kind: Secret metadata: name: mysql labels: app: mysql data: mysql-root-password: eW91cnBhc3N3b3Jk
  • 15.
    Unless otherwise indicated,these slides are © 2013 -2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ Microservice Architecture Concerns 15 • Externalized Configuration • ConfigMap and Secrets • Service Discovery • DNS, DiscoveryClient • Circuit-breaker • Distributed Tracing • Metrics • Log aggregation
  • 16.
    Unless otherwise indicated,these slides are © 2013 -2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ Microservice Runtime Management 16 •Circuit-breaker - Netflix Hystrix •Distributed Tracing - Spring Cloud Sleuth / Zipkin •Metrics - Spring Boot Actuator /Micrometer •Service Mesh - Istio •load balancing / routing •policy enforcement •telemetry and reporting
  • 17.
    Unless otherwise indicated,these slides are © 2013 -2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ Log Aggregation 17 • Spring Cloud Sleuth ‣ https://cloud.spring.io/spring-cloud-sleuth/ • Stackdriver ‣ https://kubernetes.io/docs/tasks/debug-application-cluster/logging-stackdriver/ • Elasticsearch and Kibana ‣ https://kubernetes.io/docs/tasks/debug-application-cluster/logging-elasticsearch- kibana/ • Loggly ‣ https://www.weave.works/blog/log-aggregation-kubernetes-loggly/
  • 18.
    Unless otherwise indicated,these slides are © 2013 -2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ Packaging 18 • Helm • The package manager for Kubernetes ‣https://docs.helm.sh/using_helm/#quickstart-guide • KubeApps • Discover & launch great Kubernetes-ready apps ‣https://kubeapps.com/ • Example ‣https://github.com/trisberg/boot-k8s-microservices/tree/s1p2017
  • 19.
    Unless otherwise indicated,these slides are © 2013 -2017 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by -nc/3.0/ Spring Cloud for Kubernetes 19 • Fabric8 team created spring-cloud-kubernetes • DiscoveryClient for Kubernetes • ConfigMap and Secrets PropertySource • Ribbon discovery in Kubernetes • Zipkin discovery in Kubernetes • and more … • Now available in spring-cloud-incubator on GitHub • Could join the Spring Cloud Release train for Greenwich sometime next year
  • 20.
    Learn More. StayConnected. Kubernetes for the Spring Developer - Wednesday 03:20 Room: 2024 https://github.com/spring-cloud-incubator/spring-cloud-kubernetes 20 #springone@s1p