3
4

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.

MetalLB インストール

Last updated at Posted at 2020-04-24

概要

  • k8sテスト環境構築

    MetalLB インストール

構築目次

環境

  • Rancher: v2.6.3
  • kubernetes(Client): v1.22.4
  • kubernetes(Server): v1.22.4
  • MetalLB: v0.11.0

インストール

インストール

## Namespace 作成
$ kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/v0.11.0/manifests/namespace.yaml

## metallb インストール
$ kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/v0.11.0/manifests/metallb.yaml


## 確認 ##
$ kubectl -n metallb-system get all
NAME                              READY   STATUS    RESTARTS   AGE
pod/controller-7dcc8764f4-hq8rd   1/1     Running   0          3m34s
pod/speaker-g5289                 1/1     Running   0          3m34s
pod/speaker-p8xkk                 1/1     Running   0          3m34s
pod/speaker-psq52                 1/1     Running   0          3m34s

NAME                     DESIRED   CURRENT   READY   UP-TO-DATE   AVAILABLE   NODE SELECTOR            AGE
daemonset.apps/speaker   3         3         3       3            3           kubernetes.io/os=linux   3m34s

NAME                         READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/controller   1/1     1            1           3m34s

NAME                                    DESIRED   CURRENT   READY   AGE
replicaset.apps/controller-7dcc8764f4   1         1         1       3m34s

Configmap 作成

  • LoadBalancerに割り当てるIPを設定

    (192.168.245.111 - 192.168.245.120)
    ※「metadata.name」は「config」固定
metallb-configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  namespace: metallb-system
  name: config
data:
  config: |
    address-pools:
    - name: default
      protocol: layer2
      addresses:
      - 192.168.245.111-192.168.245.120
  • Configmap 適用
$ kubectl apply -f metallb-configmap.yaml
$ kubectl get svc -n ingress-system
NAME                                          TYPE           CLUSTER-IP      EXTERNAL-IP       PORT(S)                      AGE
obi-test-ingress-nginx-controller             LoadBalancer   10.43.58.216    192.168.245.111   80:30769/TCP,443:30528/TCP   3h18m
obi-test-ingress-nginx-controller-admission   ClusterIP      10.43.146.222   <none>            443/TCP                      3h18m

動作確認

※NGINX Ingressを利用するため、Ingressのインストールが必要
リンク:Nginx Ingress インストール

  • マニフェスト作成
test-metallb.yaml
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: nginx-ingress
spec:
  ingressClassName: nginx
  rules:
  - host: nginx.test.local
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: nginx-svc
            port:
              number: 80
---
apiVersion: v1
kind: Service
metadata:
  name: nginx-svc
spec:
  selector:
    app: nginx
  ports:
  - name: http
    protocol: TCP
    port: 80
    targetPort: 80
---
apiVersion: v1
kind: Pod
metadata:
  name: nginx
  labels:
    app: nginx
spec:
  containers:
  - name: nginx
    image: nginx:1.21.4
    imagePullPolicy: IfNotPresent
    ports:
    - containerPort: 80
  • マニフェスト適用
$ kubectl apply -f test-metallb.yaml
  • hosts 設定追加
    Load BalancerのIPとIngressで設定したhostを紐づけ
$ cat /etc/hosts
........
192.168.245.111 nginx.test.local
........
  • 接続確認
$ curl -I http://nginx.test.local
HTTP/1.1 200 OK
.........
.........
3
4
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
3
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?