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

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

taxin
February 09, 2021

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

taxin

February 09, 2021
Tweet

More Decks by taxin

Other Decks in Technology

Transcript

  1. • Kubernetes Novice Tokyo #1 • ʮKubernetesΛԿΛ࢖ͬͯ৮Γ࢝ΊͨΒ͍͍͔ʯͱ͍͏ٙ໰ -> AWS, Azure,

    GCPͷϚωʔδυk8sαʔϏεͷ঺հΛߦ͏LTΛ࣮ࢪ ԿΛ࢖ͬͯK8SΛಈ͔͔͢
  2. • Ϋϥελͷཁ݅ (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
  3. • ߏஙखॱ • Node෼ͷVMΛ༻ҙ͠ɺඞཁͳίϯϙʔωϯτͷinstall + ઃఆΛߦ͍ΫϥελΛߏங - Master Node: Ϋϥελͷ؅ཧΛߦ͏

    - Worker Node: ࣗ෼ୡ͕ಈ͔͍ͨ͠ίϯςφ(ϫʔΫϩʔυ)Λ࣮ߦ͢Δ Kubernetes (1) KUBEADM VM Master Worker Worker VM VM
  4. • ߏஙखॱ • େ·͔ͳྲྀΕΛݴ͏ͱԼهͷ௨Γ • Ϋϥελߏஙલͷ؀ڥઃఆ (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
  5. • Ͱ͖Δ͜ͱ • 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
  6. • ߏஙखॱ • 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)
  7. • ߏஙखॱ • goͷinstall + kindͷinstall • kind create cluster

    • cluster໊ͷࢦఆ (--name <cluster_name>) • Cluster configϑΝΠϧͷࢦఆ (--config <filepath>) (2) KIND
  8. • Ͱ͖Δ͜ͱ • 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
  9. • Ͱ͖Δ͜ͱ • 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
  10. • ߏஙखॱ • VM্ʹγϯάϧϊʔυߏ੒ͷΫϥελʔΛίϚϯυҰͭͰ࡞੒͢Δ - brew install minikube - minikube

    start • OS X/Windows্ͰVMͷࣄલߏஙͳ͠ͰΫϥελߏங͕Մೳ (※ ֤OSͰԾ૝Խػೳ͕༗ޮʹͳ͍ͬͯΔલఏ) (3)MINIKUBE Kubernetes OS X / Windows / Linux Master + Worker
  11. • Ͱ͖Δ͜ͱ • 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
  12. • ݕূ಺༰ɺΫϥελ্Ͱಈ͔͢πʔϧ etc. ʹԠͯ͡ɺ ؀ڥΛ࢖͍෼͚Δਓ͕ଟ͍(Α͏ʹײ͡Δ) • 1) Public Cloudͷk8s؀ڥ •

    ϩʔΧϧϚγϯͷϦιʔε (Memory, CPU) ʹറΒΕͳ͍ • Public CloudͷଞαʔϏεͱͷ࿈ܞ͕Ͱ͖Δ Ͳ͏΍ͬͯ࢖͍෼͚Δ͔
  13. • πʔϧͷ࢖͍෼͚ (ݸਓͷҙݟ) • Kind / minikube: k8sʹ৮Γ࢝ΊΔਓ޲͚ ( =

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