k8s安装loadbalancer

目录

    • 前言
    • 准备
    • 安装metallb
    • 访问测试

前言

k8s集群搭建参考:
https://blog.csdn.net/centrl/article/details/134291473

准备

查看kube-proxy的strictARP模式

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

修改为true

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

安装metallb

创建命名空间

kubectl create namespace metallb-system

创建secret

kubectl create secret generic -n metallb-system memberlist --from-literal=secretkey="$(openssl rand -base64 128)"

安装

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

配置L2模式

cat > ip-pool-config.yaml << EOF
apiVersion: metallb.io/v1beta1
kind: IPAddressPool
metadata:
  name: ip-pool01
  namespace: metallb-system
spec:
  addresses:
  - 172.16.16.200-172.16.16.254
---
apiVersion: metallb.io/v1beta1
kind: L2Advertisement
metadata:
  name: l2-ip-pool01
  namespace: metallb-system
spec:
  ipAddressPools:
  - ip-pool01
EOF

创建

kubectl create -f ip-pool-config.yaml

访问测试

创建测试应用

kubectl create deploy nginx --image nginx:latest --port 80 -n default

暴露服务

kubectl expose deployment nginx --name nginx-lb --port 80 --target-port 80 --type LoadBalancer -n default

查看服务

kubectl get svc nginx-lb

集群外访问,打开浏览器访问:

http://${EXTERNAL-IP}:${PORT}
# 依本文环境地址为
http://172.16.16.200:80

删除测试数据

kubectl delete deploy nginx

删除测试服务

kubectl delete svc nginx-lb

你可能感兴趣的:(k8s,kubernetes)