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

『Docker/Kubernetes 実践コンテナ開発入門』輪読会 #5

nagaakihoshi
February 25, 2019
380

『Docker/Kubernetes 実践コンテナ開発入門』輪読会 #5

nagaakihoshi

February 25, 2019
Tweet

Transcript

  1. 5.1 Kubernetesとは 3 ホストOS Docker コンテナ1 コンテナ2 コンテナ3 ホストOS Kubernetes

    Docker Kubernetes Master Node Node1 コンテナ1 コンテナ1 コンテナ1 コンテナ2 Deployment / ReplicaSet Node2 コンテナ1 コンテナ1 コンテナ1 コンテナ2 Deployment / ReplicaSet kube apiserver etcd kube scheduler kube controller manager Service Ingress
  2. 5.2 ローカル環境でKubernetesを実行する 5 # 5.2.1 curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.10.4/bin/darwin/amd64/kubectl \ &&

    chmod +x kubectl \ && mv kubectl /usr/local/bin/ kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v1.8.3/src/deploy/recommended/kubernetes-dashbo ard.yaml kubectl get pod --namespace=kube-system -l k8s-app=kubernetes-dashboard kubectl proxy http://localhost:8001/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy/
  3. 5.6 Pod YAMLについて補足 8 配列 ハッシュ - A - B

    - - C-1 - C-2 A: a B: b C: C-1: c1 C-2: c2 [“A”, “B”, [“C-1”, “C-2”]] {“A” => “a”, “B” => “b”, “C” => {“C-1” => “c1”, “C-2” => “c2”}}
  4. 5.6 Pod 10 # 5.6.1 # simple-pod.yml apiVersion: v1 kind:

    Pod metadata: name: simple-echo spec: containers: - name: nginx image: gihyodocker/nginx-proxy:latest env: - name: BACKEND_HOST value: localhost:8000 ports: - containerPort: 80 - name: echo image: gihyodocker/echo:latest ports: - containerPort: 8080
  5. 5.6 Pod 11 # 5.6.1 kubectl apply -f simple-pod.yml kubectl

    get pod kubectl exec -it simple-echo sh -c nginx kubectl logs -f simple-echo -c echo kubectl delete pod simple-echo kubectl delete -f simple-pod.yml
  6. 5.7 ReplicaSet 12 # 5.7 # simple-replicaset.yml apiVersion: apps/v1 kind:

    ReplicaSet metadata: name: echo labels: app: echo spec: replicas: 3 selector: matchLabels: app: echo template: metadata: labels: app: echo spec: containers: - name: nginx image: gihyodocker/nginx-proxy:latest env: - name: BACKEND_HOST value: localhost:8080 ports: - containerPort: 80 - name: echo image: gihyodocker/echo:latest ports: - containerPort: 8080
  7. 5.8 Deployment 14 # 5.8 # simple-deployment.yml apiVersion: apps/v1 kind:

    Deployment metadata: name: echo labels: app: echo spec: replicas: 3 selector: matchLabels: app: echo template: metadata: labels: app: echo spec: containers: - name: nginx image: gihyodocker/nginx-proxy:latest env: - name: BACKEND_HOST value: localhost:8000 ports: - containerPort: 80 - name: echo image: gihyodocker/echo:latest ports: - containerPort: 8080
  8. 5.8 Deployment 15 # 5.8.1 kubectl apply -f simple-deployment.yml --record

    kubectl get pod,replicaset,deployment --selector app=echo kubectl rollout history deployment echo # 5.8.2 kubectl rollout history deployment echo --revision=2 kubectl rollout history deployment echo --revision=3 kubectl rollout undo deployment echo kubectl delete -f simple-deployment.yml
  9. # 5.9 # simple-replicaset-with-label.yml apiVersion: apps/v1 kind: ReplicaSet metadata: name:

    echo-spring labels: app: echo release: spring spec: replicas: 3 selector: matchLabels: app: echo release: spring template: metadata: labels: app: echo release: spring 5.9 Services 16 spec: containers: - name: nginx image: gihyodocker/nginx-proxy:latest env: - name: BACKEND_HOST value: localhost:8000 ports: - containerPort: 80 - name: echo image: gihyodocker/echo:latest ports: - containerPort: 8080 --- apiVersion: apps/v1 kind: ReplicaSet metadata: name: echo-summer labels: app: echo release: summer ...つづく
  10. 5.9 Services 17 # 5.9 kubectl apply -f simple-replicaset-with-label.yml kubectl

    get pod -l app=echo -l release=spring kubectl get pod -l app=echo -l release=summer kubectl apply -f simple-service.yml kubectl get svc echo kubectl run -i --rm --tty debug --image=gihyodocker/fundamental:0.1.0 --restart=Never -- bash -il kubectl logs -f echo-summer-8qxmg -c echo
  11. 5.10 Ingress • L4バランサー ◦ IPアドレスとポート番号による負 荷分散 • L7バランサー ◦

    URLやHTTPヘッダーで負荷分 散 18 https://academy.gmocloud.com/qa/20170810/4591
  12. 5.10 Ingress 19 # 5.10 kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/nginx-0.16.2/deploy/mandatory.yaml kubectl

    apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/nginx-0.16.2/deploy/provider/cloud-generic.yaml kubectl -n ingress-nginx get service,pod # 5.10.2 kubectl apply -f simple-service.yml kubectl get ingress curl http://localhost -H 'Host: ch05.gihyo.local'