Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Разработка cloud-native Java-приложений для Kubernetes, Егор Волков,Senior Java Developer

55 views

Published on

разработка cloud-native Java-приложений для Kubernetes.

Published in: Education
  • Be the first to comment

  • Be the first to like this

Разработка cloud-native Java-приложений для Kubernetes, Егор Волков,Senior Java Developer

  1. 1. Containers, Java and You Building cloud-native Java applications with Docker and Kubernetes
  2. 2. DISCLAIMER
  3. 3. Hello, ${username}! ● Senior Java developer @ DataArt ● Working with Java since early 2014 ● Background in networking and game development, mostly C/C++ ● Wrote first program in 2004, first network protocol in 2007 ● Interested in everything DevOps related since started working with Java
  4. 4. import all.the.tools.*; 1. Get Java https://jdk.java.net/10/ 2. Get Docker https://www.docker.com/get-started (18.06 CE +) 3. Get Kompose https://kompose.io/ 4. Get ready! BONUS STAGE: 5. Get the code: https://github.com/wollfxp/project1/tree/master-february 6. Get ready for real!
  5. 5. Evolution of Environments
  6. 6. Evolution of Environments Bare metal Virtualization (HW) Virtualization (SW) OS Container Engine JVM Your app 1. Bare metal, VM software-based, VM hardware-based 2. IaaS, PaaS, SaaS 3. Amazon Services, Amazon ECS ,Amazon EC2 4. Google Services, Google App Engine, Google Kubernetes Engine 5. CloudFoundry, Heroku, etc.
  7. 7. Evolution of Environments my-project-0.0.1-SNAPSHOT.jar app-build-2541.war ./exploded jar/ ./exploded war/ Java developers only care about these!
  8. 8. Evolution of Environments … sometimes about these also ... java version "10.0.2" 2018-07-17 Java(TM) SE Runtime Environment 18.3 (build 10.0.2+13) Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10.0.2+13, mixed mode) openjdk version "9-internal" OpenJDK Runtime Environment (build 9-internal+0-2016-04-14-195246.buildd.src) OpenJDK 64-Bit Server VM (build 9-internal+0-2016-04-14-195246.buildd.src, mixed mode)
  9. 9. 1. As long as the JRE is the same, that we develop against - everything should be fine 2. As long as the Servlet container version is the same, that we develop against - everything should be fine 3. As long as the RDBMS version is the same, that we develop against - everything should be fine 4. … Evolution of Environments
  10. 10. Evolution of Environments 1. We need to solidify versions of everything (JVM, JDK/JRE, servers, servlet containers, databases, etc) 2. There’s no good way to limit Ops people from screwing everything up 3. This should be done by software, not people 4. We already have solutions for similar problems in Java world - dependency managers!
  11. 11. Dockerization: starting small 1. Docker to the rescue! 2. Make a snapshot of your environment 3. Redistribute and run anywhere © 4. Bake internal custom service versions and builds
  12. 12. Dockerization: starting small
  13. 13. Dockerization: starting small Demo Dockerfile for “Spaceships” https://github.com/wollfxp/project1/blob/master/Dockerfile
  14. 14. Dockerization: starting small FROM openjdk:10-jre VOLUME /tmp COPY target/project1-0.0.1-SNAPSHOT.jar app.jar ENTRYPOINT ["java", "-Djava.security.egd=file:/dev/./urandom", "-jar", "/app.jar"] Run with: gradlew clean build && docker build -t starships . docker run -p 8443:8443 --name starships --network space-net starships:latest Dockerfile:
  15. 15. Dockerization: starting small Caused by: java.net.ConnectException: Connection refused: connect at java.base/java.net.DualStackPlainSocketImpl.waitForConnect(Native Method) ~[na:na] at java.base/java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:85) ~[na:na] at java.base/java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:400) ~[na:na] at java.base/java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:243) ~[na:na] at java.base/java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:225) ~[na:na] at java.base/java.net.PlainSocketImpl.connect(PlainSocketImpl.java:148) ~[na:na] at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:402) ~[na:na] at java.base/java.net.Socket.connect(Socket.java:591) ~[na:na] at com.mysql.cj.protocol.StandardSocketFactory.connect(StandardSocketFactory.java:173) ~[mysql-connector-java-8.0.11.jar:8.0.11] at com.mysql.cj.protocol.a.NativeSocketConnection.connect(NativeSocketConnection.java:66) ~[mysql-connector-java-8.0.11.jar:8.0.11] ... 58 common frames omitted WARN 2196 --- [ restartedMain] o.h.e.j.e.i.JdbcEnvironmentInitiator : HHH000342: Could not obtain connection to query metadata : Communications link failure The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
  16. 16. Dockerization: starting small This time we remember about the database! Re-Run with: gradlew clean build && docker build -t starships . docker run -p 3306:3306 -v C:/dev/docker/mysql-project1:/var/lib/mysql --env MYSQL_ROOT_PASSWORD=s3cur1ty@maks --env MYSQL_DATABASE=space --name mysql-project1 --network space-net mysql:5.6 docker run -p 8443:8443 --name starships --network space-net starships:latest
  17. 17. Dockerization: starting small
  18. 18. Dockerization: starting small
  19. 19. Dockerization: starting small
  20. 20. Dockerization: next steps Demo docker-compose file for “Spaceships” https://github.com/wollfxp/project1/blob/master/docker-compose.yml
  21. 21. Dockerization: next steps Run with: gradlew clean build && docker build -t starships . docker-compose up
  22. 22. Dockerization: next steps
  23. 23. Dockerization: next steps Hello, world with Kubernetes!
  24. 24. Kubernetes from scratch 1. Enabling Kubernetes in Docker for Windows/Docker for Mac
  25. 25. Kubernetes from scratch
  26. 26. Kubernetes from scratch 1. Enabling Kubernetes in Docker for Windows/Docker for Mac 2. Checking that everything works
  27. 27. Kubernetes from scratch $ kubectl version Client Version: version.Info{Major:"1", Minor:"10", GitVersion:"v1.10.11", GitCommit:"637c7e288581ee40ab4ca210618a89a555b6e7e9", GitTreeState:"clean", BuildDate:"2018-11-26T14:38:32Z", GoVersion:"go1.9.3", Compiler:"gc", Platform:"windows/amd64"} Server Version: version.Info{Major:"1", Minor:"10", GitVersion:"v1.10.11", GitCommit:"637c7e288581ee40ab4ca210618a89a555b6e7e9", GitTreeState:"clean", BuildDate:"2018-11-26T14:25:46Z", GoVersion:"go1.9.3", Compiler:"gc", Platform:"linux/amd64"} $ kubectl get all NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE service/kubernetes ClusterIP 10.96.0.1 443/TCP 4d
  28. 28. Kubernetes from scratch 1. Enabling Kubernetes in Docker for Windows/Docker for Mac 2. Checking that everything works 3. Running Kompose 4. Deploy to Kubernetes
  29. 29. Kubernetes and Kompose demo Let’s try it! https://github.com/wollfxp/project1/tree/master-february
  30. 30. Kubernetes from scratch
  31. 31. Kubernetes from scratch … ? Problem: we cannot reach our service! Solution: Ingress! Deploy NGINX!
  32. 32. Kubernetes from scratch … ? https://kubernetes.github.io/ingress-nginx/user-guide/tls/#ssl-passthrough
  33. 33. Kubernetes from scratch … ? Problem: we cannot reach our service! And NGINX won’t help! Solution: NodePort! Expose our service!
  34. 34. Kubernetes from scratch … ?
  35. 35. Kubernetes: next steps 1. Get rid of HTTPS in the application and use NGINX for that 2. Proper load balancing via Ingress 3. Deploy multiple types of the same instances (/app,/api,/admin) 4. Utilize namespaces to limit visibility of environments 5. Start using K8S metric API to get more info about your cluster 6. Deploy anywhere* with the same** configuration 7. Log aggregation (maybe?)
  36. 36. Questions and Answers
  37. 37. Thank you!

×