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์์ ๋ณผ์ ์์ต๋๋ค.

2. KIND ์ค์นํ๊ธฐ
- Docs/Quick-start๋ฅผ ์ฐธ๊ณ ํฉ๋๋ค.
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์ผ๋ก ์ค์น ํ์ธ.