Notice
Recent Posts
Recent Comments
Link
«   2024/09   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
Tags
more
Archives
Today
Total
관리 메뉴

클라우드 엔지니어 꿈나무

Kubernetes(K8S) LoadBalance (metallb) - Centos7 본문

kubernetes

Kubernetes(K8S) LoadBalance (metallb) - Centos7

새싹싹이 2023. 9. 17. 16:52

metallb 설치법 참고

https://metallb.universe.tf/ installation 및 configuration 부분

 


Kubernetes 내 LoadBalance 적용을 위하여 metallb 설치

metallb 사용을 위하여 Address Resolution Protocol 부분을 true로 적용

kubectl get configmap kube-proxy -n kube-system -o yaml | sed -e "s/strictARP: false/strictARP: true/" | \

yaml 파일 저장을 위하여 kubectl apply -f 가 아닌 wget 으로 다운로드

wget https://raw.githubusercontent.com/metallb/metallb/v0.13.11/config/manifests/metallb-native.yaml

kubectl apply -f metallb-native.yaml

 

yml 파일 생성

vi ipaddresspool.yml

apiVersion: metallb.io/v1beta1
kind: IPAdressPool
metadata:
  name: first-pool
  namespace: metallb-system
spec:
  addresses:
  - 10.0.0.201-10.0.0.210

vi l2adv.yml

apiVersion: metallb.io/v1beta1
kind: L2Advertisement
metadata:
  name: example
  namespace: metallb-system
spec:
  ipAddressPools:
  - first-pool

vi hosthttp.yml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: dep-http
  labels:
    env: prod 
spec:
  replicas: 3
  selector:
    matchLabels:
      app: httpd
  template:
    metadata:
      name: temp-httpd
      labels:
        app: httpd
    spec:
      containers:
      - name: h1
        image: httpd
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 80
        volumeMounts:
        - mountPath: /usr/local/apache2/htdocs
          name: kang-vol
      volumes:
      - name: kang-vol
        hostPath:
          path: /apache
          type: Directory

 

명령어 추가 입력

kubectl apply -f ipaddress.yml

kubectl apply -f l2adv.yml

kubectl apply -f hosthttp.yml

master 내 apache 폴더와 index.html 파일 생성 및 node 1~3 에 index.html 전송

mkdir /apache (master 및 node 1~3)
vi /apache/index.html

html index 파일 전달

kubectl cp /apache/index.html dep-http-7d87fdbdb-2xr8v:/usr/local/apache2/htdocs
kubectl cp /apache/index.html dep-http-7d87fdbdb-nv4j6:/usr/local/apache2/htdocs
kubectl cp /apache/index.html dep-http-7d87fdbdb-z2k6q:/usr/local/apache2/htdocs
curl 10.47.0.2
curl 10.36.0.1
curl 10.44.0.2

kubectl expose deploy dep-http --type=NodePort : NodePort로 서비스하여 노출하기
kubectl get svc : 서비스 확인

 

인터넷 창

<확인을 위하여 node 내 index.html 파일 내 webserber 뒤 번호를 수정>

LoadBalancer 적용 확인 가능