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

ローカルk8s環境のススメ / k8s-tools-for-local

B2f2e01a1eb9dd92f8ed5b2dd414a2b8?s=47 TaxiN
February 09, 2021

ローカルk8s環境のススメ / k8s-tools-for-local

B2f2e01a1eb9dd92f8ed5b2dd414a2b8?s=128

TaxiN

February 09, 2021
Tweet

Transcript

  1. @taxin_tt ϩʔΧϧK8S؀ڥͷεεϝ

  2. WHO AM I? • @taxin_tt • Kubernetes Novice Tokyoͷதͷਓ •

    ࠷ۙ͸TerraformͱDatadogΛ΍͍ͬͯΔ
  3. • Kubernetes Novice Tokyo #1 • ʮKubernetesΛԿΛ࢖ͬͯ৮Γ࢝ΊͨΒ͍͍͔ʯͱ͍͏ٙ໰ -> AWS, Azure,

    GCPͷϚωʔδυk8sαʔϏεͷ঺հΛߦ͏LTΛ࣮ࢪ ԿΛ࢖ͬͯK8SΛಈ͔͔͢
  4. ԿΛ࢖ͬͯK8SΛಈ͔͔͢

  5. ԿΛ࢖ͬͯK8SΛಈ͔͔͢

  6. • ্ͷ2ͭ͸Կ? • ϩʔΧϧ؀ڥͰk8sΫϥελΛߏங͢Δࡍʹར༻͢Δπʔϧ • ࠓճ͸্هͷ໨తͰར༻͢Δ3छྨͷπʔϧ (kubeadm, kind, minikube) Λ঺հ͠·͢

    • ͜Μͳπʔϧ͋ΔΑʂ ͜Μͳࣄ΋Ͱ͖ΔΑʂ͕͋Ε͹ #k8snovice Ͱڞ༗ͯ͠Լ͍͞ ԿΛ࢖ͬͯK8SΛಈ͔͔͢
  7. • Ϋϥελͷཁ݅ (Requirements) • 1) OS: Ubuntu 16.04+ / Debian

    9+ / CentOS 7 / Red Hat Enterprise Linux (RHEL) 7 etc. (※ OS X or Windows্Ͱಈ͔͢ࡍʹ͸VMΛཱͯͯɺͦ͜ʹಋೖ͢Δ) • 2) Memory: 2 GB (or more) / Node • 3) CPU: 2 Cores (or more) (1) KUBEADM
  8. • ߏஙखॱ • Node෼ͷVMΛ༻ҙ͠ɺඞཁͳίϯϙʔωϯτͷinstall + ઃఆΛߦ͍ΫϥελΛߏங - Master Node: Ϋϥελͷ؅ཧΛߦ͏

    - Worker Node: ࣗ෼ୡ͕ಈ͔͍ͨ͠ίϯςφ(ϫʔΫϩʔυ)Λ࣮ߦ͢Δ Kubernetes (1) KUBEADM VM Master Worker Worker VM VM
  9. • ߏஙखॱ • େ·͔ͳྲྀΕΛݴ͏ͱԼهͷ௨Γ • Ϋϥελߏஙલͷ؀ڥઃఆ (VM΁ͷkubeadmɾkubeletɾkubectlͷinstall, Nodeؒ௨৴ͷڐՄઃఆ etc.) •

    ԼهͷίϚϯυΛ༻͍֤ͯNodeͷηοτΞοϓΛߦ͏ - kubeadm init : Master NodeͷॳظԽ - kubeadm join : Worker NodeΛΫϥελʹࢀՃͤ͞Δ Kubernetes (1) KUBEADM VM Master Worker VM 1. init 2. join
  10. • Ͱ͖Δ͜ͱ • Master / Worker Nodeͷίϯϙʔωϯτͷઃఆ஋Λ্ॻ͖ͯ͠ΧελϚΠζՄೳ - yamlϑΝΠϧ಺ʹઃఆΛఆٛ͢Δ -

    kubeadm init --config config.yaml Λ࣮ߦ͢Δ (1) KUBEADM # cluster config # change IP address of APIServer apiVersion: kubeadm.k8s.io/v1beta1 kind: ClusterConfiguration kubernetesVersion: v1.16.0 apiServer: extraArgs: advertise-address: 192.168.0.103
  11. • Ͱ͖Δ͜ͱ • Master / Worker Nodeͷίϯϙʔωϯτͷઃఆ஋Λ্ॻ͖ͯ͠ΧελϚΠζՄೳ - ݸผʹ࣮ߦ࣌Ҿ਺ͱͯ͠ઃఆ஋Λ౉͢͜ͱ΋Մೳ (--apiserver-advertise-address=<ip-address>)

    https://kubernetes.io/ja/docs/setup/production-environment/tools/kubeadm/control-plane-flags/ (1) KUBEADM
  12. • ߏஙखॱ • Node༻ͷImageΛpullͯ͠ɺdocker containerΛNodeͱͯ͠ΫϥελΛߏங (Kind = Kubernetes in Docker)

    • OS X/Windows্ͰɺVMͷsetupແ͠ͰΫϥελߏங͕Մೳ (2) KIND OS X / Windows / Linux DockerHub Kubernetes Master (docker container) Worker (docker container) Worker (docker container)
  13. • ߏஙखॱ • goͷinstall + kindͷinstall • kind create cluster

    • cluster໊ͷࢦఆ (--name <cluster_name>) • Cluster configϑΝΠϧͷࢦఆ (--config <filepath>) (2) KIND
  14. • Ͱ͖Δ͜ͱ • 1. Ϋϥελͷߏ੒ ΛYAMLϑΝΠϧͰදݱͰ͖Δ (Cluster configϑΝΠϧͷࢦఆ) • ԼهͷΑ͏ͳ߲໨ΛΫϥελͷઃఆͱͯ͠ఆٛ

    - Nodeͷߏ੒ - Kubernetesͷversion (Node imageͷversion → k8sͷversion) (2) KIND # cluster config # three node (master:1 / worker:2) kind: Cluster apiVersion: kind.x-k8s.io/v1alpha4 nodes: - role: control-plane image: kindest/node:v1.16.4 - role: worker image: kindest/node:v1.16.4 - role: worker image: kindest/node:v1.16.4
  15. • Ͱ͖Δ͜ͱ • 2. ಺෦తʹkubeadmΛར༻͍ͯ͠ΔͷͰɺkubeadmͷઃఆͷ࠶ར༻͕Մೳ ( → kubeadm config patches)

    (2) KIND # cluster config(kind) kind: Cluster apiVersion: kind.x-k8s.io/v1alpha4 kubeadmConfigPatches: - | apiVersion: kubeadm.k8s.io/v1beta2 kind: ClusterConfiguration kubernetesVersion: v1.16.0 apiServer: extraArgs: advertise-address: 192.168.0.103 # cluster config(kubeadm) apiVersion: kubeadm.k8s.io/v1beta2 kind: ClusterConfiguration kubernetesVersion: v1.16.0 apiServer: extraArgs: advertise-address: 192.168.0.103
  16. • ߏஙखॱ • VM্ʹγϯάϧϊʔυߏ੒ͷΫϥελʔΛίϚϯυҰͭͰ࡞੒͢Δ - brew install minikube - minikube

    start • OS X/Windows্ͰVMͷࣄલߏஙͳ͠ͰΫϥελߏங͕Մೳ (※ ֤OSͰԾ૝Խػೳ͕༗ޮʹͳ͍ͬͯΔલఏ) (3)MINIKUBE Kubernetes OS X / Windows / Linux Master + Worker
  17. • Ͱ͖Δ͜ͱ • minikube startͷҾ਺ͱͯ͠ઃఆ஋Λ౉͢ - ex) minikube start --extra-config=kubelet.max-pods=100

    (Node͝ͱͷpod਺ͷ্ݶ) • ΫϥελͷΧελϚΠζ΋Ұ෦͚ͩՄೳ - Kubernetesͷόʔδϣϯࢦఆ ( --kubernetes-version=<version> ) - ίϯςφϥϯλΠϜͷஔ͖׵͑ ( --container-runtime=<runtime> ) - ίϯϙʔωϯτͷઃఆ஋ͷ্ॻ͖ ( --extra-config=<component.key>=<value> ) (3)MINIKUBE
  18. • ͳΜͱͳ͘ศརͦ͏ͳͷ͸Θ͔ͬͨ → Θ͔͚ͬͨͲɺ͜ΕΒͷπʔϧ͸Ͳ͏΍ͬͯ࢖͍෼͚ͨΒ͍͍ͷ? Ͳ͏΍ͬͯ࢖͍෼͚Δ͔

  19. • ݕূ಺༰ɺΫϥελ্Ͱಈ͔͢πʔϧ etc. ʹԠͯ͡ɺ ؀ڥΛ࢖͍෼͚Δਓ͕ଟ͍(Α͏ʹײ͡Δ) • 1) Public Cloudͷk8s؀ڥ •

    ϩʔΧϧϚγϯͷϦιʔε (Memory, CPU) ʹറΒΕͳ͍ • Public CloudͷଞαʔϏεͱͷ࿈ܞ͕Ͱ͖Δ Ͳ͏΍ͬͯ࢖͍෼͚Δ͔
  20. • 2) ϩʔΧϧͷk8s؀ڥ • Managed k8sαʔϏεͱൺֱͯ͠ΫϥελͷProvisioningͷ͕࣌ؒൺֱత୹͍ • ηΩϡϦςΟ໘Ͱͷߟྀ (ରԠ) ͕جຊతʹෆཁ

    Ͳ͏΍ͬͯ࢖͍෼͚Δ͔
  21. • πʔϧͷ࢖͍෼͚ (ݸਓͷҙݟ) • Kind / minikube: k8sʹ৮Γ࢝ΊΔਓ޲͚ ( =

    ؀ڥߏஙࣗମͰͭ·ͮ͘͜ͱ͕গͳ͍ɺΑΓߏ੒͕γϯϓϧͳͷ͸minikube) • kubeadm : KubernetesࣗମͷཧղΛਂΊ͍ͨਓ޲͚ (kubeadm init/joinͰԿΛ΍͍ͬͯΔ͔? kubeadm-config.yaml Λ༻͍ͨΫϥελͷઃఆ etc. ) • Public Cloud: ϩʔΧϧ؀ڥͷ੍໿ʹҾ͔͔ͬΔΑ͏ͳ಺༰Λݕূ͍ͨ͠ਓ޲͚ (Public CloudͷଞαʔϏεͱ࿈ܞ͍ͤͨ͞৔߹͸ݴΘͣ΋͕ͳ) Ͳ͏΍ͬͯ࢖͍෼͚Δ͔
  22. HAPPY K8S LIFE!