Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
kindでも"type LoadBalancer"を使いたい! / kubernetes-me...
Search
uesyn
October 24, 2019
Programming
0
1.6k
kindでも"type LoadBalancer"を使いたい! / kubernetes-meetup-tokyo-24-kind-with-type-loadbalancer
Kubernetes Meetup Tokyo #24 の LTで使った資料です。
uesyn
October 24, 2019
Tweet
Share
More Decks by uesyn
See All by uesyn
PodSecurityPolicyの安全な移行の道のり / On the safe migration of PodSecurityPolicy
uesyn
1
1.1k
PodSecurityPolicyの廃止に備えて、 一足先にPodSecurity Admissionを試してみよう! / from-psp-to-podsecurity
uesyn
4
1.7k
Kubernetes v1.19 変更点調査のまとめ / k8s-v119-updates
uesyn
1
240
そのクラスタ本当にアップグレードして大丈夫? Storage Version の更新も忘れずにしよう! / k8s-storage-version-migration
uesyn
2
3.7k
次世代のログ基盤 Grafana Lokiを始めよう! / prometheus-meetup-tokyo-3-lets-start-the-loki
uesyn
7
15k
Loki入門
uesyn
8
2.6k
Cortexの話をKubeConで聞きたかったっていう話
uesyn
4
2k
kubernetesでGPUを 管理するために スケジューラをいじってみた
uesyn
2
2.8k
Other Decks in Programming
See All in Programming
Language Server と喋ろう – TSKaigi 2025
pizzacat83
2
670
複数アプリケーションを育てていくための共通化戦略
irof
2
700
#QiitaBash TDDでAIに設計イメージを伝える
ryosukedtomita
2
1.6k
DevDay2025-OracleDatabase-kernel-addressing-history
oracle4engineer
PRO
7
1.6k
TypeScript を活かしてデザインシステム MCP を作る / #tskaigi_after_night
izumin5210
4
480
〜可視化からアクセス制御まで〜 BigQuery×Looker Studioで コスト管理とデータソース認証制御する方法
cuebic9bic
2
270
CRUD から CQRS へ ~ 分離が可能にする柔軟性
tkawae
0
230
ユーザーにサブドメインの ECサイトを提供したい (あるいは) 2026年函館で一番熱くなるかもしれない言語の話
uvb_76
0
180
Javaに鉄道指向プログラミング (Railway Oriented Pro gramming) のエッセンスを取り入れる/Bringing the Essence of Railway-Oriented Programming to Java
cocet33000
1
120
Devinで実践する!AIエージェントと協働する開発組織の作り方
masahiro_nishimi
6
2.6k
Feature Flag 自動お掃除のための TypeScript プログラム変換
azrsh
PRO
4
630
がんばりすぎないコーディングルール運用術
tsukakei
1
180
Featured
See All Featured
Building a Scalable Design System with Sketch
lauravandoore
462
33k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
Fashionably flexible responsive web design (full day workshop)
malarkey
407
66k
Why You Should Never Use an ORM
jnunemaker
PRO
56
9.4k
Designing for humans not robots
tammielis
253
25k
Site-Speed That Sticks
csswizardry
7
590
Mobile First: as difficult as doing things right
swwweet
223
9.6k
How to Ace a Technical Interview
jacobian
276
23k
Embracing the Ebb and Flow
colly
85
4.7k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
34
3k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
30
2.1k
GraphQLの誤解/rethinking-graphql
sonatard
71
11k
Transcript
kindでも ”type LoadBalancer” が使いたい!
Profile 2 上村 真也 • 所属: Z Lab • Twitter: @uesyn
3
このスライドは個人の見解であり、 所属する組織の公式見解ではありません。 4
5 kind • DockerコンテナをノードとしてK8sクラスタを作成 ◦ マルチノードの構成も可能 • 詳しくは以下の@amsy810さんの資料を参照 ◦ “Kubernetes
in Docker で始めるお手軽 Kubernetes 環境” https://speakerdeck.com/masayaaoyama/cloudnativejp-09-kubernetes-in-docker-kind
6 "type LoadBalancer"なService • LoadBalancerとServiceをいい感じに繋ぐ • それぞれの環境にあった実装がなければ利用できない
7 • “type LoadBalancer”は利用できない ◦ Cloud Providerの実装やLBのコントローラを持ってないはず … • 設定しないと接続できるのはAPI
Serverのみ ◦ NodePortへの接続も設定が必要 kindと”type LoadBalancer” kindでも”type LoadBalancer”を使いたい!
“type LoadBalancer”な Serviceへのアクセス 8 “type LoadBalancerを…” 3. MetalLBを利用 4. カスタムコントローラを実装
1. NodePortとextraPortMappings 2. kubectl port-forward 諦める 諦めない
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 諦める
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
MetalLBを利用 11 • Linux環境であればMetalLBのL2-modeを使うと"type LoadBalancer"が利用可能 • Docker Desktopではdockerのnetworkに疎通が難しくMetalLBは難しい ◦ https://mauilion.dev/posts/kind-metallb/
諦めない
12 Macを使っていても手軽に"type LoadBalancer"が使えないか?
カスタムコントローラを実装した 13 Pod1 Pod2 Pod3 LBPod K8s API Server port-forward
ClusterIP • Podとして動かしたLBでトラフィックをバランシング ◦ そのLBのPodに対してPortForward ◦ バランシングにはCluster-IPを利用 ◦ kubectl port-forwardと同じくTCPのみ対応 ◦ API Serverにつながれば良いだけ! 諦めない
実装の概要 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を作成
15 デモ • したいけど多分時間ない • 気になる人はあとで個別で見に来てください • ソースコードは後ほど展開します ◦ 現在Private
Repository ◦ https://github.com/uesyn/k8s-local-loadbalancer
16 ご静聴ありがとうございました!