kubernetes超入門 with java

Download Kubernetes超入門 with java

Post on 21-Jan-2018

364 views

Category:

Technology

4 download

Embed Size (px)

TRANSCRIPT

  • Kubernetes with Java

    Kubernetes

    Java

    #hirojug

  • 1

    5Oracle Code Japan Tour in HiroshimaCloud Native Java EEKubernetes

    Kubernetes

    KubernetesKubernetes

  • 1.

  • 3

    KubernetesKubernetesSpring BootREST API

    Kubernetes

    Kubernetes

    Kubernetes

    (Docker)

    Spring Boot

    REST API

    Java

  • 4

    Kubernetes

    Pod

    Replica Set

    Deployment

    Service

    ServiceBlue/Green Deployment

    2018

  • 2. Kubernetes

  • 6

    miniKube

    Windows exe (minikube-windows-amd64.exe) https://github.com/kubernetes/minikube/releases

  • 7

    Docker

    Google/BorgApache

    Blue Green Deployment Rolling Update

    Kubernetesk8s

    8Ks

    Kubernetes

  • 8

    20146

    201571.0

    20157Linux FoundationCloud Native Computing Foundation(CNCF)(AT&TCiscoCoreOSDockerIBMIntelMicrosoftRed HatVMware)

    20178AWSCNCF

  • 9

    AWSMicrosoft AzureGoogle Cloud PlatformIBM BluemixCNCFKubernetes

    KubernetesDocker SwarmAmazon EC2 Container Service

  • 10

    GCPAWSk8s

    Open Container InitiativeDocker

    CPU

    Kubernetes

  • 11

    Ingress

    Kubernetes

    Cluster

    Node

    Pod

    Service

    Ingress

    internet

    Node

    Pod

    Node

    Pod

    Service

  • 12

    Node/ClusterNodek8sVMk8sNodeNodeCliuter

    Podk8sPodNodek8sPodNode

    Podlocalhost

    Pod

    Label:k8sPod

    Kubernetes[1/3]

  • 13

    ServicePodIPk8sServicePodk8s

    Service

    ClusterIP:()

    NodePort:IPNodePort

    LoadBalancer:(minikube)

    ExternalName:DNSCNAME1.7kube-dns

    Kubernetes[2/3]

  • 14

    IngressIngressServiceServiceHTTPL7URLSSLIngressk8sGCPGCPAWSAWS

    Replica SetPodPod/

    DeploymentPodReplication SetsDeploymentDeployment Controller

    Kubernetes

    Kubernetes[3/3]

  • 3.

  • 16

    Minikubek8sVMk8(Kubernetes Master)k8s

    Minikube

    (Linux,Mac OS,Windows)

    VM(VirtualMachine)

    Kubernetes(minikube)

    Kubernetes MasterNode

    (1)

  • 17

    virtualBox

    minikube

    miniKube

    Windows exe (minikube-windows-amd64.exe) https://github.com/kubernetes/minikube/releases

    minikube

    minikube-windows-amd64.exeminikube.exe

    vm driver VirtualBox

    kubectl

    URL kubectl.exe

    vm driver VirtualBox

    Kubernetes

    Windowskubernetes

    $ minikube config set vm-driver virtualbox

    $ minikube start

    $ minikube version

  • 4.

  • 19

    DockerSpring BootREST APIDockerKubernetes

    Docker

    docker.io/uls555/getting-started-k8s-with-java

    Docker Hub

    Docker Image

    InternetREST API

    minikube

    push

    pull

  • 20

    REST API

    REST API

    Docker Hub

    Docker Image

    InternetREST API

    minikube

  • 21

    PodPodYAML

    Pod

    pod.yaml

    Pod

    Pod

    PodIP

    DashboardURL:http://192.168.99.100:30000

    Pod[1/2]

    apiVersion: v1kind: Podmetadata:

    name: rest-apispec:

    containers:- image: docker.io/uls555/getting-started-k8s-with-java:v1

    imagePullPolicy: Alwaysname: rest-api

    $ kubectl create -f pod.yaml

    $ kubectl get podsNAME READY STATUS RESTARTS AGErest-api 0/1 ContainerCreating 0 1m

  • 22

    Pod

    Pod[2/2]

    $ kubectl delete pod rest-api

  • 23

    PodPodReplica SetPod

    Replica Set

    replicaset.yaml

    Replica Set

    Replica Set[1/2]

    apiVersion: extensions/v1beta1kind: ReplicaSetmetadata:

    name: rest-api-rsspec:

    replicas: 3template:metadata:

    labels:app: my-rest-api

    spec:containers:

    - image: docker.io/uls555/getting-started-k8s-with-java:v1imagePullPolicy: Alwaysname: rest-api

    $ kubectl create -f replicaset.yaml

    Pod

    Pod

  • 24

    Pod

    PodReplica SetPodPodPod

    Pod

    Replica Set

    Replica Set[2/2]

    $ kubectl get podNAME READY STATUS RESTARTS AGErest-api-rs-6xpqf 1/1 Running 0 1mrest-api-rs-m1x43 1/1 Running 0 1mrest-api-rs-pbsmk 1/1 Running 0 1m

    $ kubectl delete pod rest-api-rs-m1x43$ kubectl get podNAME READY STATUS RESTARTS AGErest-api-rs-6xpqf 1/1 Running 0 4mrest-api-rs-m1x43 1/1 Terminating 0 4mrest-api-rs-n92wz 0/1 ContainerCreating 0 5srest-api-rs-pbsmk 1/1 Running 0 4m

    Pod

    Pod

    $ kubectl delete replicaset rest-api-rs

  • 25

    Replica Setk8sDeploymentk8s

    Deployment

    deployment.yaml

    Deployment[1/3]

    apiVersion: apps/v1beta1kind: Deploymentmetadata:

    name: rest-api-depspec:

    replicas: 3template:metadata:

    labels:app: my-rest-api

    spec:containers:

    - image: docker.io/uls555/getting-started-k8s-with-java:v1imagePullPolicy: Alwaysname: rest-api

    RepulicsSet

    $ kubectl create -f deployment.yaml

  • 26

    Pod

    Deployment

    Replicas4

    Deployment[2/3]

    $ kubectl get podsNAME READY STATUS RESTARTS AGErest-api-rs-6xpqf 1/1 Running 1 9hrest-api-rs-n92wz 1/1 Running 1 9hrest-api-rs-pbsmk 1/1 Running 1 9h

    apiVersion: apps/v1beta1kind: Deploymentmetadata:

    name: rest-api-depspec:

    replicas: 4template:metadata:

    labels:app: my-rest-api

    spec:containers:

    - image: docker.io/uls555/getting-started-k8s-with-java:v1imagePullPolicy: Alwaysname: rest-api

    replica4

  • 27

    Deployment

    Deployment

    Pod

    Pod14

    Deployment[3/3]

    $ kubectl get podsNAME READY STATUS RESTARTS AGErest-api-rs-6xpqf 1/1 Running 1 9hrest-api-rs-9b0sl 1/1 Running 0 10srest-api-rs-fbcdf 0/1 ContainerCreating 0 10srest-api-rs-pbsmk 1/1 Running 1 9h

    $ kubectl apply -f deployment.yaml

  • 28

    ServicePodPod

    Service

    service.yaml

    Service

    Service

    Service[1/3]

    kind: ServiceapiVersion: v1metadata:

    name: rest-api-servicespec:type: NodePort

    selector:app: my-rest-api

    ports:- port: 8080

    targetPort: 8080

    $ kubectl create -f service.yaml

    ServiceNodeportminikubeLoadBalancer

    PodLavelapp:my-rest-apiPod

    ServicePod

    $ kubectl get servicesNAME CLUSTER-IP EXTERNAL-IP PORT(S) AGEkubernetes 10.0.0.1 443/TCP 11hrest-api-service 10.0.0.51 8080:31372/TCP 1m

  • 29

    Service

    NodeIP

    Deployment

    v2

    Service[2/3]

    $ minikube ip192.168.99.100

    http://192.168.99.100:31372

    apiVersion: apps/v1beta1kind: Deploymentmetadata:name: rest-api-dep

    spec:replicas: 4template:metadata:labels:

    app: my-rest-apispec:containers:

    - image: docker.io/uls555/getting-started-k8s-with-java:v2imagePullPolicy: Alwaysname: rest-api

    v2

  • 30

    Deployment

    Deployment

    Deployment

    Service[3/3]

    $ kubectl apply -f deployment.yamldeployment "rest-api-dep" replaced

    $ curl 192.168.99.100:31372{"message":"Hello World!","version":"v2"}

    $ kubectl rollout undo deployment/rest-api-depdeployment "rest-api-dep" rolled back

    $ curl 192.168.99.100:31372{"message":"Hello World!","version":"v1"}

  • 31

    Deployment Blue/Green DeploymentService

    Deployment

    deployment-v3.yaml

    ServiceBlue/Green Deployment[1/2]

    apiVersion: apps/v1beta1kind: Deploymentmetadata:

    name: rest-api-dep-v3spec:

    replicas: 3template:metadata:

    labels:app: my-rest-api-v3

    spec:containers:

    - image: docker.io/uls555/getting-started-k8s-with-java:v1imagePullPolicy: Alwaysname: rest-api

    Deploymentv3

    $ kubectl create f deployment-v3.yaml

  • 32

    Deployment

    Service

    ServicePodselector

    ServiceBlue/Green Deployment[2/2]

    $ kubectl get deploymentNAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGErest-api-dep 4 4 4 4 3hrest-api-dep-v3 4 4 4 4 23m

    kind: ServiceapiVersion: v1metadata:

    name: rest-api-servicespec:type: NodePort

    selector:app: my-rest-api-v3

    ports:- port: 8080

    targetPort: 8080

    PodLavelapp:my-rest-api-v3Pod

    $ kubectl apply -f service.yamlservice "rest-api-service" configured$ curl 192.168.99.100:31372{"message":"Hello World!","version":"v3"}

  • 5.

  • 34

    minikube start

    Node

    .minikubeminikube

    $ minikube stop$ minikube delete$ minikube start

  • 35

    WEB

    Using Kubernetes on Google Container Enginehttps://www.slideshare.net/enakai/using-kubernetes-on-google-container-engine

    Docker2 Kuberneteshttps://oss.sios.com/yorozu-blog/yorozu-20151216

    DockerKuberneteshttp://tech.uzabase.com/entry/2015/02/13/180743

    minikube Windows Kubernetes http://takaya030.hatenablog.com/entry/2017/04/30/191727

    kubernetes http://sssslide.com/speakerdeck.com/sgeengineer/kubernetesdebian-warukai-fa-sutairu-maikurosabisuziyanakutemoiiziyanai

    Kuberneteshttp://qiita.com/t-yotsu/items/f565b2d788a3b98fe762

    Google Cloud Platform

    WEB+DB-PRESS Vol.99