我在 Ubuntu 服务器上以 vanilla 安装的形式运行 microk8s 实例,配置了 MetalLB 以动态分配 10.0.2.1 到 10.0.2.200,并启用了 Nginx 入口控制器。我已在此实例上安装了 wordpress helm chart(https://github.com/bitnami/charts/tree/master/bitnami/wordpress/#installing-the-chart),命令如下:
helm install wordpress \
--set wordpressUsername=admin \
--set wordpressPassword=password \
--set mariadb.mariadbRootPassword=secretpassword \
--set ingress.enabled=true \
--set ingress.hostname=wordpress.internal \
bitnami/wordpress
服务已成功启动并运行,当我运行
kubectl describe services wordpress
我得到以下信息:
Name: wordpress
Namespace: default
Labels: app.kubernetes.io/instance=wordpress
app.kubernetes.io/managed-by=Helm
app.kubernetes.io/name=wordpress
helm.sh/chart=wordpress-9.3.10
Annotations: meta.helm.sh/release-name: wordpress
meta.helm.sh/release-namespace: default
Selector: app.kubernetes.io/instance=wordpress,app.kubernetes.io/name=wordpress
Type: LoadBalancer
IP: 10.152.183.73
LoadBalancer Ingress: 10.0.2.1
Port: http 80/TCP
TargetPort: http/TCP
NodePort: http 31799/TCP
Endpoints: 10.1.70.14:8080
Port: https 443/TCP
TargetPort: https/TCP
NodePort: https 30087/TCP
Endpoints: 10.1.70.14:8443
Session Affinity: None
External Traffic Policy: Cluster
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal IPAllocated 32m metallb-controller Assigned IP "10.0.2.1"
Normal nodeAssigned 6m41s (x3 over 31m) metallb-speaker announcing from node "k8s"
当我通过 SSH 连接到安装了 microk8s 的节点时,实例的响应与我预期的一致:
curl 10.0.2.1
<!DOCTYPE html>
<html class="no-js" lang="en-US">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0" >
<link rel="profile" href="https://gmpg.org/xfn/11">
<title>User's Blog! – Just another WordPress site</title>
但是,当我在联网的 Macbook 上运行相同的命令时,我无法得到响应:
curl 10.0.2.1
curl: (7) Failed to connect to 10.0.2.1 port 80: Operation timed out
答案1
注意到以下两种方法有效后:
- 通过 portforward 访问(使用以下命令在浏览器中导航到 localhost:8080)
kubectl port-forward *podname-here* 8080:8080
- NodePort(导航到浏览器k8s-master-ip:31799)
我将问题归结为分配给 metallb 的 IP 范围。问题是我为 metallb 分配的 IP 范围 (10.0.2.1-10.0.2.200) 超出了消费者路由器 (Apple Airport Extreme) 中配置的子网掩码。一旦我将 IP 范围更改为路由器允许的子网 (10.0.1.100-10.0.1.150) 内的 IP 范围,导航到服务 IP 即可正常运行。