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

Kubernetes超入門 with java

Kubernetes超入門 with java

2017.10.27 広島Javaユーザーグループ で行ったKubernetes ハンズオン資料です。

Yasunari Tanaka

October 27, 2017
Tweet

More Decks by Yasunari Tanaka

Other Decks in Technology

Transcript

  1. 1 -  - $! +# &(#  - ,%+&",

    Java),,*,% '*   Twitter-@7richi
  2. 2 5:)Oracle Code Japan Tour in Hiroshima*;)Cloud Native Java EE*LMJRT7KubernetesD14SFPIVNETHNQD56&,4

    .UUU Kubernetes:%16+=@ .-544>'3; 7.CB4-+ =@7/6,9-54;. -54(W?>X 307'Kubernetes:%2A 9;8  ;OTKGTD "16Kubernetes<!#14,8 ,=2( $;
  3. 4 ▪ Kubernetes.+CE7A-Kubernetes5%)Spring Boot*  %'REST API5%)9D=?6E8<>BE;@D5&4 ▪:EA – Kubernetes.

    – CE7A0Kubernetes.#43"-,4 – Kubernetes5%',9D=?6E8<>BE;@D. ▪%,!$+ – 9D=?(Docker)-&4 – Spring Boot.  . – REST API-(!)  . +:EA $$%,!+ 12/Java+/ ,!.*/
  4. 5 -2/=5 ▪Kubernetes& ▪<>1; & ▪8=30= – Pod#&69<. – Replica

    Set+69<. – Deployment+69<. – Service& – Service+Blue/Green Deployment ▪  – 0>9=4:7>2018? ▪  – *# )!$(% – "',
  5. 8 mOp_uZzizJ n[xFDockerNG<IB=LYxbe"N =L[\bo{YxbeUzX\dvz[rxazu|1 GoogleA-/+:M@5LYxbeWs\_[\bo2Borg3AF gShSN/;@-:M>1GApachesQ]x\A, :M@5L Uzlx^z\^kdSTOA4L1 nQWwZzj\NEclwQ0O`lczd=L$B;@0YxbeF Uzd\Xzu0

    Blue Green Deployment 0 Rolling Update DCF$ N7@5L1 ?DHE2Kubernetes3G0Vt[q(A2%F!32 #y,#3B56 94LB:M12k8s3B:M'*:ML9 51 {8GK8KsF.F N&;@5L| )HG2WzmzfPb\3J2WRifPb\3} KubernetesBG
  6. 9 ▪2014 66 ▪2015 76.5*141.0335+ ▪2015 76Linux Foundation&Cloud Native Computing

    Fou ndation(CNCF)%  (AT&TCiscoCoreOSDockerIBMIntelMicrosoftRed HatVM ware$#&%  () ▪2017 86AWSCNCF%04.5&/2,- "  )'!& $
  7. 10 ]udh+O NQR4 Wlq\v_ouOeltXP%N>4) %N*;SQ:NMGF5A<A1O/$JP,OWlq\v_ouU. @ CIHO^vj`KAIBS-=8S5w!NmX[t^vj`%MW ltvbJPxE?J]udh0O.= KMR2O&ML/$3 U(AF

    4,]udhU'#BS_`dn=-KMGF5 6AWS76Microsoft Azure76Google Cloud Platform76IBM Bluemix7ML O-[pYgltiXav=CNCFONMGFNQR4"OK?T]u dhZv\`fsv_oucvrKAIKubernetesPekV[fK9;SN MRHH8S ▪KubernetesOZv\`fsv_oucvr Docker Swarm4Amazon EC2 Container ServiceML=8S MD]udhZv\`fsv_oucvr=-NMGFO<
  8. 11 ▪1%PGOCa…frgp} – d„y%YGCPAAWSLBJKXk8s_;GK7A='H]M(RUM `N)&GOC ▪j„ru2PGOCj„ru1% – j„ru2%Q8 PZ\Open Container

    InitiativeE<WKC]j„ ru#LB^SDockerQj„ru2LXZC ▪3zmtPj„ru_sy‚c – NQzmtPNQj„ru_>H]D_@0 ▪j„ru?Qvqtƒ…g,$† 6!XV‡ – k…xmsbmew€…+Q- ▪j„ruQ"*5 – j„ruE`I[Aj„ru_. L4: ▪j„ruQ9/ – -Q3j„ruTQagnmw„l„h- ▪j„ruQ€o…ma‚i…l~„ – j„ru PCPU€o…mY{|€…€o…mQ - KubernetesR_GKF^]QD
  9. 12 ▪ %   #Ingress $ Kubernetes  Cluster

    Node Pod " ! Service Ingress internet Node Pod " ! Node Pod " ! Service
  10. 13 ▪Node/Cluster Node^cIk8sbv€„n‡ŽpVlYgbVM`KT24w…bR^J k8sn94Vl‰=dIŠxN) Vl \bv€„NRmj Node]@SmlJNodebHnCliuter^e ▪Pod k8s]b‡Žpb,!JPodc“ bv€„bH]INode

    a"FSmlk8s-b0$J Podb3#c&TYv€„c \+aUNodea‡ŽpSmlJRm aik<VlA*b‡Ž{z‘v€„’]1%SmY“Zbo‡uy‹ ]LKnBZQhVPT“ZbH^T\‡Žp/l ‘”…z‡Žry^o‡uy‹Io‡uy‹b†Ž‚^…sq ƒ`_b:W’ – Pod bv€„clocalhost;6]D ]Ol – EMj8(Podfcos{zc/`K – Label:k8s]94Sm\Kl|zc>a[O?7a.I‡ŽpS mlNXbGaŒ~ˆ`N?7a'jmlIXmjnBZQhVPVlY gPoda T\}tnVlR^N/l Kubernetesb5C[1/3]
  11. 14 ▪Service $Pod?8; IPK]hVJ G;Hk8s@"<.!? ServiceB@KRWV3Pod?G 5FIH@<ik]_ejT@?H #1/k8s<ATk`V[LVQ_fJ9H:@fXkV=7I;0H – Service@

    - ▪ ClusterIP:ReVY)?Tk`VJ*8C9/6@J(9H=.ReVY2F@ DTk`V?KRWV<4C9([aPg\) ▪ NodePort: ^k]IP?+>ck\<Tk`VJ*8C9/ <NodeIP>l<NodePort>J%9H6=?EG.ReVY2FNodePortTk`V? KRWV<4C9 ▪ LoadBalancer:ReN]bi_MZ@ik]_ejTJ8;)?Tk`VJ* 8C9(minikubeA,) ▪ ExternalName:DNS@CNAMEhSk]J&9H6=?EG.ReVY) 5@OM fKVJ9H/6I?A_kUdj1.7@kube-dns3% Kubernetes@'[2/3]
  12. 15 ▪Ingress IngressYServiceW[]ICAdServiceW{€joNaDHTTP €‚vx|nW- MR8LbREa,CL7SXURLyq‚W_a~‚ sfl^SSL43 /VUX<]7FaD\PCIngressYk8sH2M REa0W_QR*6T8HGcaCGCPSYGCPXCAWSSYAWS X0W QPS{€joH

    Lba ▪Replica Set PodX{}i$ƒPodXmsw$„d5!/=Na*6DmswH" MP{}i$_`]VE Y%PWmswd? MCFNJRa Ymswd BM{}i$d5!Na ▪Deployment Pod^Replication SetsX:er{t‚u*6d#DDeploymenth zpgkuS(Na.d;@NbZDeployment ControllerH9+M P.W&MRKba OXW]Kubernetes'X)C1>H$Na KubernetesX1>[3/3]
  13. 17 Minikube"k8s)#&   %'8=.=! $ ;=*:7/=<!VM k8+901!,<24) '$ !-=6(Kubernetes

    Master)5=3!k8s+901) (' >Minikube " Ingress" ? Minikube" ;=*:7/=< (Linux,Mac OS,Windows) VM(VirtualMachine) Kubernetes(minikube) Kubernetes Master Node (1!#)
  14. 18 ▪ – virtualBox 4Q<BRO#1(0"* ▪minikube-=@B3@H – miniKube-?5QPRC ▪ Windows

    - exe (minikube-windows-amd64.exe) https://github.com/kubernetes/minikube/releases – minikube- ▪ minikube-windows-amd64.exe2minikube.exe *NDRJ$(F<-'&G7 O?,! ▪ AG7OB- vm driver 2 VirtualBox ,%0&.-9IQC  – kubectl 4Q<BRO#1(+-)6MRK@=R; #10 – #1&URL / kubectl.exe 2?5QPRC$(F<-'&G7O?, –  vm driver 2 VirtualBox ,%0&.9IQC2 %0 ▪Kubernetes8M<>- – -9IQC)8M<>2%0 – -9IQC):RERER;LQ2 &/ Windows,kubernetes 2%0 $ minikube config set vm-driver virtualbox $ minikube start $ minikube version
  15. 20 /8*#8 Docker6()-4 Spring Boot REST APIDocker"29(! Kubernetes&8+.#9%)- 69'38! 

    ▪Docker6()-4 – docker.io/uls555/getting-started-k8s-with-java ▪,07" /8*#8 Docker Hub 79$51'98 Docker Image  REST API minikube push pull   
  16. 21  REST API  REST API  Docker Hub

      Docker Image   REST API minikube
  17. 22 /%-Pod,6 4+Pod,@EL86#'04J>M< - GCD9<A).5YAML ($4 ▪Pod, ) – ,

    (pod.yaml6 – Pod6 ▪Pod, – ",Pod-:I<?,EI8FMAIP7BK<#!&'*,(!3- 7:=<* – Dashboard(1#'02NURL:http://192.168.99.100:30000O Pod(,@EL8[1/2] apiVersion: v1 kind: Pod metadata: name: rest-api spec: containers: - image: docker.io/uls555/getting-started-k8s-with-java:v1 imagePullPolicy: Always name: rest-api $ kubectl create -f pod.yaml $ kubectl get pods NAME READY STATUS RESTARTS AGE rest-api 0/1 ContainerCreating 0 1m 8HM;,
  18. 24 Pod/ "$Pod  "$+, /%$ +*) !.*Replica Set/"&+Pod/ #-

    ▪Replica Set+ ( – + 'replicaset.yaml/ – Replica Set/ Replica Set/"$1230[1/2] apiVersion: extensions/v1beta1 kind: ReplicaSet metadata: name: rest-api-rs spec: replicas: 3 template: metadata: labels: app: my-rest-api spec: containers: - image: docker.io/uls555/getting-started-k8s-with-java:v1 imagePullPolicy: Always name: rest-api $ kubectl create -f replicaset.yaml  #-Pod+ Pod+ 
  19. 25 ▪Pod  ▪Pod  Replica SetPod " Pod" 

    Pod – Pod ▪Replica Set Replica Set" $%&#[2/2] $ kubectl get pod NAME READY STATUS RESTARTS AGE rest-api-rs-6xpqf 1/1 Running 0 1m rest-api-rs-m1x43 1/1 Running 0 1m rest-api-rs-pbsmk 1/1 Running 0 1m $ kubectl delete pod rest-api-rs-m1x43 $ kubectl get pod NAME READY STATUS RESTARTS AGE rest-api-rs-6xpqf 1/1 Running 0 4m rest-api-rs-m1x43 1/1 Terminating 0 4m rest-api-rs-n92wz 0/1 ContainerCreating 0 5s rest-api-rs-pbsmk 1/1 Running 0 4m !Pod !Pod $ kubectl delete replicaset rest-api-rs
  20. 26 Replica Set0!/$  k8s&-%Deployment0 !/$&,.6;?2' k8s&/"+'9A4=@& & /$/ ▪Deployment'

    $6;?2 – ' #deployment.yaml0 – 6;?2 Deployment0 "6;?2[1/3] apiVersion: apps/v1beta1 kind: Deployment metadata: name: rest-api-dep spec: replicas: 3 template: metadata: labels: app: my-rest-api spec: containers: - image: docker.io/uls555/getting-started-k8s-with-java:v1 imagePullPolicy: Always name: rest-api <8:357:12>( RepulicsSet$)* $ kubectl create -f deployment.yaml
  21. 27 ▪Pod  ▪Deployment  – Replicas  4 

    Deployment   [2/3] $ kubectl get pods NAME READY STATUS RESTARTS AGE rest-api-rs-6xpqf 1/1 Running 1 9h rest-api-rs-n92wz 1/1 Running 1 9h rest-api-rs-pbsmk 1/1 Running 1 9h apiVersion: apps/v1beta1 kind: Deployment metadata: name: rest-api-dep spec: replicas: 4 template: metadata: labels: app: my-rest-api spec: containers: - image: docker.io/uls555/getting-started-k8s-with-java:v1 imagePullPolicy: Always name: rest-api replica  4 
  22. 28 ▪Deployment – Deployment  ▪Pod – Pod14  Deployment

    [3/3] $ kubectl get pods NAME READY STATUS RESTARTS AGE rest-api-rs-6xpqf 1/1 Running 1 9h rest-api-rs-9b0sl 1/1 Running 0 10s rest-api-rs-fbcdf 0/1 ContainerCreating 0 10s rest-api-rs-pbsmk 1/1 Running 1 9h $ kubectl apply -f deployment.yaml  
  23. 29 Service7 (,&62- (*Pod7+0/(*8=;97 5..3/#407Pod/)5 ▪Service0 . – 0 -service.yaml7

    – Service7 ▪Service0 Service0 [1/3] kind: Service apiVersion: v1 metadata: name: rest-api-service spec: type: NodePort selector: app: my-rest-api ports: - port: 8080 targetPort: 8080 $ kubectl create -f service.yaml Service01Nodeport7)5 minikube-1LoadBalancer1 Pod0Lavel/ app:my-rest-api!$ '6,"5Pod7%5 )5Service0<=:.Pod0<=:7 %5 $ kubectl get services NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE kubernetes 10.0.0.1 <none> 443/TCP 11h rest-api-service 10.0.0.51 <nodes> 8080:31372/TCP 1m
  24. 30 ▪ Service  – Node IP –  

    ▪Deployment   –  v2  Service [2/3] $ minikube ip 192.168.99.100 http://192.168.99.100:31372 apiVersion: apps/v1beta1 kind: Deployment metadata: name: rest-api-dep spec: replicas: 4 template: metadata: labels: app: my-rest-api spec: containers: - image: docker.io/uls555/getting-started-k8s-with-java:v2 imagePullPolicy: Always name: rest-api v2 
  25. 31 ▪Deployment –  ▪ Deployment &)-'!"%+ #/  $*&0'

    .0,/ $*&0'   –  ▪Deployment.0-($ – .0-($ –  Service[3/3] $ kubectl apply -f deployment.yaml deployment "rest-api-dep" replaced $ curl 192.168.99.100:31372 {"message":"Hello World!","version":"v2"} $ kubectl rollout undo deployment/rest-api-dep deployment "rest-api-dep" rolled back $ curl 192.168.99.100:31372 {"message":"Hello World!","version":"v1"}
  26. 32 Deployment0 #.!'&:<9;31586<7+% )- ,/( Blue/Green Deployment*(0- +Service 0"-. .

    ▪)Deployment0 – * &deployment-v3.yaml0 – 68:2 Service0"$Blue/Green Deployment[1/2] apiVersion: apps/v1beta1 kind: Deployment metadata: name: rest-api-dep-v3 spec: replicas: 3 template: metadata: labels: app: my-rest-api-v3 spec: containers: - image: docker.io/uls555/getting-started-k8s-with-java:v1 imagePullPolicy: Always name: rest-api Deployment* '4 30v3)  $ kubectl create –f deployment-v3.yaml
  27. 33 – Deployment ▪Service – ServicePod  selector  –

     ServiceBlue/Green Deployment[2/2] $ kubectl get deployment NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE rest-api-dep 4 4 4 4 3h rest-api-dep-v3 4 4 4 4 23m kind: Service apiVersion: v1 metadata: name: rest-api-service spec: type: NodePort selector: app: my-rest-api-v3 ports: - port: 8080 targetPort: 8080 PodLavel app:my-rest-api-v3 Pod  $ kubectl apply -f service.yaml service "rest-api-service" configured $ curl 192.168.99.100:31372 {"message":"Hello World!","version":"v3"}
  28. 35 ▪minikube start%* – Node  –   

    ”.minikube”!("& minikube  "%#'$* ) $ minikube stop $ minikube delete $ minikube start
  29. 36 >  ▪ WEB1-5 – Using Kubernetes on Google

    Container Engine https://www.slideshare.net/enakai/using-kubernetes-on-google-container-engine – Docker& %$2 @Kubernetes@ https://oss.sios.com/yorozu-blog/yorozu-20151216 – Docker0=46, )!(Kubernetes http://tech.uzabase.com/entry/2015/02/13/180743 – minikube Windows " Kubernetes , ) http://takaya030.hatenablog.com/entry/2017/04/30/191727 – kubernetes +)23-; 9-.<1?72'!&'! http://sssslide.com/speakerdeck.com/sgeengineer/kubernetesdebian-warukai-fa-sutairu- maikurosabisuziyanakutemoiiziyanai – Kubernetes +*) http://qiita.com/t-yotsu/items/f565b2d788a3b98fe762 ▪  – 8</:9#%#Google Cloud Platform – WEB+DB-PRESS Vol.99