官方安装说明
https://docs.k0sproject.io/stable/examples/metallb-loadbalancer/
https://metallb.universe.tf/installation/#preparation
检测网络模式
vi /etc/k0s/k0s.yaml
默认iptables
不需要修改, 如果你是ipvs网络模式需要修改strictARP:true (修改方式转到最后)
节点之间必须允许端口7946(TCP和UDP)。此外,在安装MetalLB之前,请确保节点上的端口7946上没有运行其他软件,例如docker守护进程。
apiVersion: k0s.k0sproject.io/v1beta1
kind: ClusterConfig
metadata:
name: k0s
spec:
extensions:
helm:
repositories:
- name: metallb
url: https://charts.bitnami.com/bitnami
charts:
- name: metallb
chartname: metallb/metallb
namespace: metallb
#使用bitnami
helm repo add bitnami https://charts.bitnami.com/bitnami
#官方源(国内下不了)
#helm repo add metallb https://metallb.github.io/metallb
#阿里云(也不行)
#helm repo add aliyun https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts
helm repo update
#查看版本和前缀
helm search repo metallb
#helm操作命令
helm repo list
#helm repo remove stable
#直接安装(报错),不使用文件直接安装即可
#helm install metallb metallb/metallb -f /dataF/k0s_files/metallb-values.yaml
#helm install metallb bitnami/metallb -f /dataF/k0s_files/metallb-values.yaml
#使用以下命令安装
k create namespace metallb
helm install metallb bitnami/metallb -n metallb
kg all -n metallb
修改镜像为能拉到的镜像,或者自己部署一个私有镜像
k edit deployment/metallb-controller -n metallb
k edit daemonset/metallb-speaker -n metallb
k edit svc/metallb-webhook-service -n metallb
#### 安装成功查看
kg po -A
kg svc -A
---
apiVersion: metallb.io/v1beta1
kind: IPAddressPool
metadata:
name: first-pool
namespace: metallb
spec:
addresses:
- 172.16.122.64-172.16.122.64 # 定义可以负载的机器IP
---
apiVersion: metallb.io/v1beta1
kind: L2Advertisement
metadata:
name: example
namespace: metallb
kubectl apply -f /dataF/k0s_files/metallb-l2-pool.yaml
apiVersion: v1
kind: Namespace
metadata:
name: web
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: web-server
namespace: web
spec:
selector:
matchLabels:
app: web
template:
metadata:
labels:
app: web
spec:
containers:
- name: httpd
image: nginx:1.21.6-alpine
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: web-server-service
namespace: web
spec:
selector:
app: web
ports:
- protocol: TCP
port: 80
targetPort: 80
type: LoadBalancer
kubectl apply -f /dataF/k0s_files/metallb-demo.yaml
查看
kubectl get service -n web
可以看到部署的指的外部ip
curl http://172.16.122.64
默认情况下,k0s使用Kube-Router CNI运行,只要不使用MetalLB的BGP模式,它就与MetalLB兼容。如果您是在IPVS模式下使用Kube-proxy,则需要在Kube-proxys中启用严格的ARP模式:
apiVersion: k0s.k0sproject.io/v1beta1
kind: ClusterConfig
metadata:
name: k0s
spec:
network:
kubeProxy:
mode: ipvs
ipvs:
strictARP: true
如果你在IPVS模式下使用 kube-proxy,那么从Kubernetes v1.14.2开始,你必须启用严格的ARP模式。
注意,如果你使用kube-router 作为服务代理,你不需要这个,因为默认情况下它启用了严格的ARP。
您可以通过在当前集群中编辑kube-proxy配置来实现这一点:
kubectl edit configmap -n kube-system kube-proxy
#找到以下项
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
# actually apply the changes, returns nonzero returncode on errors only
kubectl get configmap kube-proxy -n kube-system -o yaml | \
sed -e "s/strictARP: false/strictARP: true/" | \
kubectl apply -f - -n kube-system