0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

KubernetesにてLoad balancerを構築

Posted at

installation

https://metallb.universe.tf/installation/
$ kubectl edit configmap -n kube-system kube-proxy

Enter the text below

apiVersion: kubeproxy.config.k8s.io/v1alpha1
kind: KubeProxyConfiguration
mode: "ipvs"
ipvs:
  strictARP: true

以下のコマンドを実行する事によって、上記の設定が出来る。

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

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

$ kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/v0.13.7/config/manifests/metallb-native.yaml

shell scriptでもOK

#!/bin/bash
export KUBECONFIG=/etc/kubernetes/admin.conf
source ~/.bashrc
kubectl get configmap kube-proxy -n kube-system -o yaml | \
sed -e "s/strictARP: false/strictARP: true/" | \
kubectl diff -f - -n kube-system

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

kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/v0.13.9/config/manifests/metallb-native.yaml

creating congmap, IPAddressPool, L2ADvertisement

apiVersion: v1
kind: ConfigMap
metadata:
  namespace: metallb-system
  name: config
data:
  config: |
    ipaddress-pools:
    - name: default
      protocol: layer2
      addresses:
      - 192.168.0.150-192.168.0.200
      autoAssign: true
apiVersion: metallb.io/v1beta1
kind: IPAddressPool
metadata:
  name: default
  namespace: metallb-system
spec:
  addresses:
  - 192.168.0.150-192.168.0.200
  autoAssign: true
---

creating deployment manifest

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: nginx-metallb
  name: nginx-metallb
spec:
  selector:
    matchLabels:
      app: nginx-metallb
  template:
    metadata:
      labels:
        app: nginx-metallb
    spec:
      containers:
      - image: nginx
        name: nginx-metallb
        ports:
        - containerPort: 80

creating service manifest

apiVersion: v1
kind: Service
metadata:
  labels:
    app: nginx-metallb
  name: nginx-metallb
spec:
  ports:
  - port: 80
    protocol: TCP
    targetPort: 80
  selector:
    app: nginx-metallb
  type: LoadBalancer
  #externalIPs:
  #- 172.24.20.61
status:
  loadBalancer: {}

By creating configgmap, IPAddressPool, L2ADvertisement, the IP address of service Loadbalancercan get it without configuration.

Reference Site

coredns設定例

apiVersion: v1
kind: Service
metadata:
  name: coredns-service-tcp
  annotations:
    metallb.universe.tf/allow-shared-ip: "coredns-service-ip"
spec:
  type: LoadBalancer
  loadBalancerIP: 172.16.0.2
  ports:
    - name: tcp
      port: 53
      targetPort: 53
      protocol: TCP
  selector:
    app: coredns
---
apiVersion: v1
kind: Service
metadata:
  name: coredns-service-udp
  annotations:
    metallb.universe.tf/allow-shared-ip: "coredns-service-ip"
spec:
  type: LoadBalancer
  loadBalancerIP: 172.16.0.2
  ports:
    - name: udp
      port: 53
      targetPort: 53
      protocol: UDP
  selector:
    app: coredns
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?