我使用Kubeadm和3个液滴在Digitalocean上创建了一个集群。由于这不是Digital ocean的托管Kubernetes集群,如何手动设置LoadBalancer?
我尝试通过将以下行添加到部署配置文件中来添加外部负载均衡器
kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 13d
mongo-mongodb-replicaset ClusterIP None <none> 27017/TCP 3h15m
mongo-mongodb-replicaset-client ClusterIP None <none> 27017/TCP 3h15m
nodejs-nodeapp LoadBalancer 10.109.213.98 <pending> 80:31769/TCP 61m
kubectl describe svc nodejs-nodeapp
Name: nodejs-nodeapp
Namespace: default
Labels: app.kubernetes.io/instance=nodejs
app.kubernetes.io/managed-by=Tiller
app.kubernetes.io/name=nodeapp
app.kubernetes.io/version=1.0
helm.sh/chart=nodeapp-0.1.0
Annotations: <none>
Selector: app.kubernetes.io/instance=nodejs,app.kubernetes.io/name=nodeapp
Type: LoadBalancer
IP: 10.109.213.98
Port: http 80/TCP
TargetPort: http/TCP
NodePort: http 31769/TCP
Endpoints: 10.244.2.19:8080
Session Affinity: None
External Traffic Policy: Cluster
Events: <none>
kubectl get pods
NAME READY STATUS RESTARTS AGE
mongo-mongodb-replicaset-0 1/1 Running 0 3h18m
mongo-mongodb-replicaset-1 1/1 Running 0 3h17m
mongo-mongodb-replicaset-2 1/1 Running 0 3h16m
nodejs-nodeapp-7b89db8888-sjcbq 1/1 Running 0 65m
kubectl describe pod nodejs-nodeapp
Name: nodejs-nodeapp-7b89db8888-sjcbq
Namespace: default
Priority: 0
PriorityClassName: <none>
Node: worker-02/206.81.3.65
Start Time: Sun, 14 Jun 2020 11:21:07 +0100
Labels: app.kubernetes.io/instance=nodejs
app.kubernetes.io/name=nodeapp
pod-template-hash=7b89db8888
Annotations: <none>
Status: Running
IP: 10.244.2.19
Controlled By: ReplicaSet/nodejs-nodeapp-7b89db8888
Containers:
nodeapp:
Container ID: docker://f0d4d01f....
Image: turfff/node-replicas:latest
Image ID: docker-pullable://turfff/node-replicas@sha256:34d...
Port: 8080/TCP
Host Port: 0/TCP
State: Running
Started: Sun, 14 Jun 2020 11:21:08 +0100
Ready: True
Restart Count: 0
Liveness: http-get http://:http/sharks delay=0s timeout=1s period=10s #success=1 #failure=3
Readiness: http-get http://:http/sharks delay=0s timeout=1s period=10s #success=1 #failure=3
Environment:
MONGO_USERNAME: <set to the key 'MONGO_USERNAME' in secret 'nodejs-auth'> Optional: false
MONGO_PASSWORD: <set to the key 'MONGO_PASSWORD' in secret 'nodejs-auth'> Optional: false
MONGO_HOSTNAME: <set to the key 'MONGO_HOSTNAME' of config map 'nodejs-config'> Optional: false
MONGO_PORT: <set to the key 'MONGO_PORT' of config map 'nodejs-config'> Optional: false
MONGO_DB: <set to the key 'MONGO_DB' of config map 'nodejs-config'> Optional: false
MONGO_REPLICASET: <set to the key 'MONGO_REPLICASET' of config map 'nodejs-config'> Optional: false
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from nodejs-nodeapp-token-4wxvd (ro)
Conditions:
Type Status
Initialized True
Ready True
ContainersReady True
PodScheduled True
Volumes:
nodejs-nodeapp-token-4wxvd:
Type: Secret (a volume populated by a Secret)
SecretName: nodejs-nodeapp-token-4wxvd
Optional: false
QoS Class: BestEffort
Node-Selectors: <none>
Tolerations: node.kubernetes.io/not-ready:NoExecute for 300s
node.kubernetes.io/unreachable:NoExecute for 300s
Events: <none>
但是,当我运行配置并检查创建的svc
{{1}}
它无法创建负载均衡器。如何手动设置LoadBalancer?
答案 0 :(得分:2)
我不建议手动配置负载均衡器。如果安装digital ocean cloud controller manager(这是DigitalOcean的Kubernetes云控制器管理器实现),则可以使其自动化。了解有关云控制器管理器here的更多信息。
DigitalOcean云控制器管理器运行服务控制器,该服务控制器负责监视LoadBalancer
类型的服务并创建DO负载均衡器以满足其需求。 Here是如何使用它的示例。
Here是一个Yaml文件,可用于将其部署到Kubernetes集群上。这需要将数字海洋api令牌放置在清单的access-token:
部分中。