Kind

Kubernetes Service(2): LoadBalancer(MetalLB)

  • kkumtree

2024-10-02T12:54:17+09:00

์ง€๋‚œ ํฌ์ŠคํŒ…, Kubernetes Service(1): ClusterIP/NodePort์— ์ด์–ด LoadBalancer Type์„ ๊ฐ€๋ณ๊ฒŒ ์‚ดํŽด๋ณด๊ณ , MetalLB๋ฅผ ๊ฐ€๋ณ๊ฒŒ ๋ถ™์—ฌ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

CloudNet@์—์„œ ์ง„ํ–‰ํ•˜๊ณ  ์žˆ๋Š” K8s Advanced Network Study(์ดํ•˜, KANS)๋ฅผ ํ†ตํ•ด ํ•™์Šตํ•œ ๋‚ด์šฉ์„ ์ •๋ฆฌํ•ฉ๋‹ˆ๋‹ค.

1. LoadBalancer Type

Service(1)์—์„œ ์–ธ๊ธ‰๋œ ๋ถ€๋ถ„์€ ๊ฑฐ๋‘์ ˆ๋ฏธํ•˜๊ณ , ์ถ”๊ฐ€๋กœ ์ ์„ ์ˆ˜ ์žˆ๋Š” ๋ถ€๋ถ„์ด ์žˆ๋‹ค๋ฉด, ์•„๋ž˜ ํ•œ ์ค„์ด ์žˆ์Šต๋‹ˆ๋‹ค.

You can define a LoadBalancer Service by disabling the load balancer NodePort allocation.

๊ธ€์ž ๊ทธ๋Œ€๋กœ LB์˜ NodePort ํ• ๋‹น์„ ๋น„ํ™œ์„ฑํ•˜์—ฌ, LoadBalancer Service๋ฅผ ์ •์˜ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
Disabling load balancer NodePort allocation ๋ฌธ์„œ๋ฅผ ์‚ดํŽด๋ณด๋‹ˆ,
v1.24๋ถ€ํ„ฐ Stable ์ƒํƒœ๋กœ ๋ณด์ž…๋‹ˆ๋‹ค.

iptables monitoring with Grafana (Not Completed)

  • kkumtree

2024-09-29T13:35:13+09:00

iptables๋ฅผ ์ˆ˜์ง‘ํ•˜์—ฌ Grafana๋กœ ํ‘œํ˜„ํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์•Œ์•„๋ด…๋‹ˆ๋‹ค.

CloudNet@์—์„œ ์ง„ํ–‰ํ•˜๊ณ  ์žˆ๋Š” K8s Advanced Network Study(์ดํ•˜, KANS)๋ฅผ ํ†ตํ•ด ํ•™์Šตํ•œ ๋‚ด์šฉ์„ ์ •๋ฆฌํ•ฉ๋‹ˆ๋‹ค.

0. ํ™˜๊ฒฝ ๊ตฌ์„ฑ (kind)

์ž‘์„ฑ์‹œ๊ฐ„ ์ด์Šˆ๋กœ featureGates, ConfigPatches, networking ์„ค์ • ์„ค๋ช…์€ ์Šคํ‚ต…ํ•ฉ๋‹ˆ๋‹ค.

a. 1 Master, 3 Slave ํ™˜๊ฒฝ ๊ตฌ์„ฑ

cat <<EOT> kind-svc-1w.yaml
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
featureGates:
  "InPlacePodVerticalScaling": true
  "MultiCIDRServiceAllocator": true
nodes:
- role: control-plane
  labels:
    mynode: control-plane
    topology.kubernetes.io/zone: ap-northeast-2a
  extraPortMappings:
  - containerPort: 30000
    hostPort: 30000
  - containerPort: 30001
    hostPort: 30001
  - containerPort: 30002
    hostPort: 30002
  kubeadmConfigPatches:
  - |
    kind: ClusterConfiguration
    apiServer:
      extraArgs:
        runtime-config: api/all=true
    controllerManager:
      extraArgs:
        bind-address: 0.0.0.0
    etcd:
      local:
        extraArgs:
          listen-metrics-urls: http://0.0.0.0:2381
    scheduler:
      extraArgs:
        bind-address: 0.0.0.0
  - |
    kind: KubeProxyConfiguration
    metricsBindAddress: 0.0.0.0
- role: worker
  labels:
    mynode: worker1
    topology.kubernetes.io/zone: ap-northeast-2a
- role: worker
  labels:
    mynode: worker2
    topology.kubernetes.io/zone: ap-northeast-2b
- role: worker
  labels:
    mynode: worker3
    topology.kubernetes.io/zone: ap-northeast-2c
networking:
  podSubnet: 10.10.0.0/16
  serviceSubnet: 10.200.1.0/24
EOT

kind create cluster --config kind-svc-1w.yaml --name myk8s --image kindest/node:v1.31.0

b. ๊ธฐ๋ณธ ํˆด ์„ค์น˜

docker exec -it myk8s-control-plane sh -c 'apt update && apt install tree psmisc lsof wget bsdmainutils bridge-utils net-tools ipset ipvsadm nfacct tcpdump ngrep iputils-ping arping git vim arp-scan -y'

1. prometheus stack ์„ค์น˜ (helm)

a. repository ์ถ”๊ฐ€ ๋ฐ ๊ตฌ์„ฑ

helm repo add prometheus-community https://prometheus-community.github.io/helm-charts

cat <<EOT > monitor-values.yaml
prometheus:
  prometheusSpec:
    podMonitorSelectorNilUsesHelmValues: false
    serviceMonitorSelectorNilUsesHelmValues: false
    nodeSelector:
      mynode: control-plane
    tolerations:
    - key: "node-role.kubernetes.io/control-plane"
      operator: "Equal"
      effect: "NoSchedule"


grafana:
  defaultDashboardsTimezone: Asia/Tokyo
  adminPassword: kans7969

  service:
    type: NodePort
    nodePort: 30002
  nodeSelector:
    mynode: control-plane
  tolerations:
  - key: "node-role.kubernetes.io/control-plane"
    operator: "Equal"
    effect: "NoSchedule"

defaultRules:
  create: false
alertmanager:
  enabled: false

EOT 

b. ์„ค์น˜

kubectl create ns monitoring
helm install kube-prometheus-stack prometheus-community/kube-prometheus-stack --version 62.3.0 -f monitor-values.yaml --namespace monitoring

c. prometheus ์ฝ˜์†” ์ ‘์†

์ƒˆ๋กœ์šด ํ„ฐ๋ฏธ๋„์„ ์—ด์–ด, port-forwarding์„ ํ†ตํ•ด ์ ‘์†ํ•ฉ๋‹ˆ๋‹ค.

KIND ํ†บ์•„๋ณด๊ธฐ

  • kkumtree

2024-09-03T21:16:07+09:00

ํ†บ์•„๋ณด๋‹ค(์šฐ๋ฆฌ๋ง์ƒ˜) ๋Š” ์˜์™ธ๋กœ ํ‘œ์ค€์–ด๋ผ๊ณ  ํ•ฉ๋‹ˆ๋‹ค.

KIND ์„ค์น˜ ์ดํ›„์— ๊ธฐ๋ณธ์ ์ธ ๋‚ด์šฉ์„ ์‚ดํŽด๋ด…๋‹ˆ๋‹ค.

CloudNet@์—์„œ ์ง„ํ–‰ํ•˜๊ณ  ์žˆ๋Š” K8s Advanced Network Study(์ดํ•˜, KANS)๋ฅผ ํ†ตํ•ด ํ•™์Šตํ•œ ๋‚ด์šฉ์„ ์ •๋ฆฌํ•ฉ๋‹ˆ๋‹ค.

0. $KUBECONFIG

  • $KUBECONFIG ํ™˜๊ฒฝ๋ณ€์ˆ˜๊ฐ€ ์—†์„ ๊ฒฝ์šฐ:
    ๋ณดํ†ต์€ ~/.kube ๋””๋ ‰ํ† ๋ฆฌ๊ฐ€ ์ƒ์„ฑ๋ฉ๋‹ˆ๋‹ค.
    ํ™•์ธํ•ด๋ณด๋‹ˆ, config ๊ฐ’๊ณผ ๋”๋ถˆ์–ด, cache ๋””๋ ‰ํ† ๋ฆฌ๋„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์—ˆ์Šต๋‹ˆ๋‹ค.

    โฏ find ~/.kube -maxdepth 2 -type f -exec ls -ld "{}" \;
    -rw------- 1 kkumtree kkumtree 44 Sep  3 21:31 /home/kkumtree/.kube/config
    โฏ find ~/.kube -maxdepth 2 -type d -exec ls -ld "{}" \;
    drwxr-x--- 3 kkumtree kkumtree 4096 Sep  3 21:31 /home/kkumtree/.kube
    drwxr-x--- 4 kkumtree kkumtree 4096 Sep  3 21:11 /home/kkumtree/.kube/cache
    drwxr-x--- 5 kkumtree kkumtree 4096 Sep  3 21:28 /home/kkumtree/.kube/cache/discovery
    drwxr-x--- 3 kkumtree kkumtree 4096 Sep  3 21:28 /home/kkumtree/.kube/cache/http
    
  • KIND์šฉ $KUBECONFIG ์„ค์ •:
    ๊ทธ๋ž˜์„œ ์•„๋ž˜์ฒ˜๋Ÿผ, ๊ฒฝ๋กœ๋ฅผ ๋งŒ๋“ค๊ณ  $KUBECONFIG ํ™˜๊ฒฝ๋ณ€์ˆ˜๋ฅผ ์„ค์ •ํ•ด์ฃผ์—ˆ์Šต๋‹ˆ๋‹ค.

๋ฆฌ๋ˆ…์Šค์— KIND ์„ค์น˜ํ•˜๊ธฐ w/golang

  • kkumtree

2024-09-02T00:33:19+09:00

Helm ์„ค์น˜ ์ถ”๊ฐ€

CloudNet@์—์„œ ์ง„ํ–‰ํ•˜๊ณ  ์žˆ๋Š” K8s Advanced Network Study(์ดํ•˜, KANS)์— ์ฐธ์—ฌํ•˜๊ฒŒ ๋˜๋ฉด์„œ ๊ธฐ๋ก์„ ๋‚จ๊ธฐ๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.

์ด๋ฒˆ์—๋Š” kind(Kubernetes IN Docker)๋ฅผ Golang์„ ํ†ตํ•ด ์„ค์น˜ํ•˜๋ฉด์„œ ์•ฝ๊ฐ„์˜ ์†Œ?๋ž€์ด ์žˆ์—ˆ๋˜ ๋ถ€๋ถ„๋งŒ ๋‹ค๋ฃน๋‹ˆ๋‹ค.

1. KIND๋ž€?

  • ์•„๋ž˜ ์‚ฌ์ง„์œผ๋กœ ๋Œ€์ฒดํ•ฉ๋‹ˆ๋‹ค. ์ž์„ธํ•œ ๋‚ด์šฉ์€ Docs/Initial_design์—์„œ ๋ณผ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

Concept

2. KIND ์„ค์น˜ํ•˜๊ธฐ

Linux์˜ ๊ฒฝ์šฐ, ํŒจํ‚ค์ง€ ๊ด€๋ฆฌ์ž ์„ค์น˜๊ฐ€ ์—†์–ด ๋ฐ”์ด๋„ˆ๋ฆฌ, ํ˜น์€ ์†Œ์Šค๋กœ ์„ค์น˜ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

์•„๋ž˜ ๋‘ ๋ฌธ์žฅ์— ๋ญ”๊ฐ€ ๋ฐœ๋™ํ•˜์—ฌ Go ์–ธ์–ด๋กœ ์„ค์น˜๋ฅผ ํ•ด๋ณด๊ธฐ๋กœ ํ–ˆ์Šต๋‹ˆ๋‹ค.

If you are a go developer you may find the go install option convenient.

Otherwise we supply downloadable release binaries, community-managed packages, and a source installation guide.

3. ์„ค์น˜๋Š” ๋งค์šฐ ๊ฐ„๋‹จ

  • Go ๊ฐœ๋ฐœ์ž๋Š” ์•„๋‹ˆ์ง€๋งŒ, ์ž˜ ๊น”๋ ค์žˆ์—ˆ๊ณ  ๊ทธ GOPATH ํ™˜๊ฒฝ๋ณ€์ˆ˜๋„ ํ™•์ธ๋ฉ๋‹ˆ๋‹ค. ๋ฌด์Šจ์ผ์ด๋žŒ.
โฏ go version
go version go1.22.2 linux/amd64
โฏ go env GOPATH
/home/kkumtree/go
  • Docs๋ฅผ ์ž˜ ์ฝ๊ณ , ์•„๋ž˜์™€ ๊ฐ™์ด ์„ค์น˜ํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค.
go install sigs.k8s.io/[email protected]

4. ์ด๊ฑธ๋กœ ๋ ์ผ๋ฆฌ๊ฐ€ ์—†๋‹ค. ํ™˜๊ฒฝ๋ณ€์ˆ˜ ์„ค์ •

  • ๊ทธ๋Ÿฐ ๊ฑด ์กด์žฌํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. Go๋ฅผ ๊ฐœ๋ฐœ์— ์‚ฌ์šฉํ•ด๋ณธ ์ ์ด ์—†์œผ๋ฉด ์•„๋ž˜์ฒ˜๋Ÿผ Go ๋ฐ”์ด๋„ˆ๋ฆฌ๊ฐ€ PATH ํ™˜๊ฒฝ๋ณ€์ˆ˜์— ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค.
โฏ env | grep go
PATH=/home/kkumtree/go/bin:/home/kkumtree/.tfenv/bin:/home/kkumtree/.tfenv/bin:/home/kkumtree/.tfenv/bin:/home/kkumtree/.sdkman/candidates/java/current/bin:/home/kkumtree/.nvm/versions/node/v18.15.0/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/bin

(a์•ˆ) ~/.bashrc์— ์ •์  ์ง€์ •

  • ๋ณดํ†ต ์ด๋ ‡๊ฒŒํ•˜๋ฉด, ์‚ฌ์šฉํ•˜๋Š”๋ฐ ๋ณ„ ๋ฌธ์ œ๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค.
echo 'export PATH=$PATH:/home/kkumtree/go/bin' >> ~/.bashrc
# zsh์ผ ๊ฒฝ์šฐ) exec bash
source ~/.bashrc
# zsh์ผ ๊ฒฝ์šฐ, ๋‹ค์‹œ zsh๋กœ ๋ณต๊ท€) exec zsh

(b์•ˆ) ~/.profile์— ๋™์  ์ง€์ •

  • ๋ณ„๋‹ค๋ฅธ ์ด์œ ๋Š” ์—†๊ณ , profile์— ์กฐ๊ฑด ์„ค์ •์ด ๋˜์–ด์žˆ์–ด์„œ ์ถ”๊ฐ€ํ•ด๋ณด์•˜์Šต๋‹ˆ๋‹ค.
  • ๋งˆ์ง€๋ง‰ 3์ค„๋งŒ ์ถ”๊ฐ€๋กœ ์ž‘์„ฑ
# โฏ cat ~/.profile
# ~/.profile: executed by the command interpreter for login shells.
# This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login
# exists.
# see /usr/share/doc/bash/examples/startup-files for examples.
# the files are located in the bash-doc package.

# the default umask is set in /etc/profile; for setting the umask
# for ssh logins, install and configure the libpam-umask package.
#umask 022

# if running bash
if [ -n "$BASH_VERSION" ]; then
    # include .bashrc if it exists
    if [ -f "$HOME/.bashrc" ]; then
	. "$HOME/.bashrc"
    fi
fi

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
    PATH="$HOME/bin:$PATH"
fi

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/.local/bin" ] ; then
    PATH="$HOME/.local/bin:$PATH"
fi

# set PATH so it includes user's gopath if it exists
if [ -x "/usr/bin/go" ] && [ -d "$(/usr/bin/go env GOPATH)/bin" ] ; then
    PATH="$(/usr/bin/go env GOPATH)/bin:$PATH"
fi

source ~/.profile๋กœ ์ ์šฉํ•œ ํ›„, kind version์œผ๋กœ ์„ค์น˜ ํ™•์ธ.

kkumtree

Source code on GitHub

ยฉ 2025 kkumtree and contributors All rights reserved.
Licensed under
CC BY-NC-ND 4.0