如何将负载均衡器添加到数字海洋上的集群



我使用 Kubeadm 和 3 个液滴在 digitalocean 上创建了一个集群。由于这不是来自数字海洋的托管 Kubernetes 集群,因此如何手动设置负载均衡器?

我尝试通过将以下行添加到部署配置文件来添加外部负载均衡器

...
replicaCount: 1
image:
repository: turfff/node-replicas
tag: latest
pullPolicy: IfNotPresent
...
service:
type: LoadBalancer
port: 80
targetPort: 8080
...

但是,当我运行配置并检查创建的 svc 时

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>

它无法创建负载均衡器。如何手动设置负载均衡器?

我不建议手动配置负载均衡器。如果您安装数字海洋云控制器管理器,则可以自动执行此操作,这是DigitalOcean的Kubernetes云控制器管理器实现。在此处阅读有关云控制器管理器的更多信息。

DigitalOcean云控制器管理器运行服务控制器,该服务控制器负责监视类型LoadBalancer的服务并创建DO负载均衡器以满足其要求。以下是如何使用它的示例。

这是一个 yaml 文件,可用于将其部署到 Kubernetes 集群上。这需要将数字海洋 api 令牌放置在清单access-token:部分。

最新更新