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

kindでも"type LoadBalancer"を使いたい! / kubernetes-meetup-tokyo-24-kind-with-type-loadbalancer

uesyn
October 24, 2019

kindでも"type LoadBalancer"を使いたい! / kubernetes-meetup-tokyo-24-kind-with-type-loadbalancer

Kubernetes Meetup Tokyo #24 の LTで使った資料です。

uesyn

October 24, 2019
Tweet

More Decks by uesyn

Other Decks in Programming

Transcript

  1. 3

  2. 5 kind • DockerコンテナをノードとしてK8sクラスタを作成 ◦ マルチノードの構成も可能 • 詳しくは以下の@amsy810さんの資料を参照 ◦ “Kubernetes

    in Docker で始めるお手軽 Kubernetes 環境” https://speakerdeck.com/masayaaoyama/cloudnativejp-09-kubernetes-in-docker-kind
  3. 7 • “type LoadBalancer”は利用できない ◦ Cloud Providerの実装やLBのコントローラを持ってないはず … • 設定しないと接続できるのはAPI

    Serverのみ ◦ NodePortへの接続も設定が必要 kindと”type LoadBalancer” kindでも”type LoadBalancer”を使いたい!
  4. NodePortとextraPortMappings 9 • ホストとNodeコンテナのPortをマッピング ◦ NodePort経由でPodへ接続できる • Serviceを作るときNodePortを意識する必要 kind: Cluster

    apiVersion: kind.sigs.k8s.io/v1alpha3 nodes: - role: control-plane - role: worker extraPortMappings: - containerPort: 80 hostPort: 80 listenAddress: "0.0.0.0" # Optional, defaults to "0.0.0.0" protocol: udp # Optional, defaults to tcp 諦める
  5. kubectl port-forward 10 • API Server経由でNode上のPodへ ◦ TCPのみ対応 • Serviceも指定できるが...

    ◦ Service配下のどれか1つのPodへPortForward Pod1 Pod2 Pod3 K8s API Server kubectl port-forward 諦める 例) kubectl port-forward svc/test-service 10000:9000
  6. カスタムコントローラを実装した 13 Pod1 Pod2 Pod3 LBPod K8s API Server port-forward

    ClusterIP • Podとして動かしたLBでトラフィックをバランシング ◦ そのLBのPodに対してPortForward ◦ バランシングにはCluster-IPを利用 ◦ kubectl port-forwardと同じくTCPのみ対応 ◦ API Serverにつながれば良いだけ! 諦めない
  7. 実装の概要 14 • コントローラはローカルのコマンドとして実行 LocalLB-controller ・"type LoadBalancer"なServiceをwatch ・上記ServiceのLBPodを作成 ・LBPodへPort-forward LBPod

    kind:Service Spec: type: LoadBalancer K8s API Server Port-Forward ・ServiceをownerReferenceとして持つ ・ServiceがなくなればGCされる ・コントローラを実行 ・"type LoadBalancer"なServiceを作成