【发布时间】:2022-01-03 13:49:13
【问题描述】:
作为the kubernetes.io docs state about a Service of type LoadBalancer:
在支持外部负载平衡器的云提供商上,设置 LoadBalancer 的 type 字段为您的 服务。负载均衡器的实际创建发生 异步的,关于预配平衡器的信息是 发布在服务的
.status.loadBalancer字段中。
在 AWS Elastic Kubernetes Service (EKS) 上,预置了一个 AWS 负载均衡器,用于对网络流量进行负载均衡(see AWS docs 和 the example project on GitHub provisioning a EKS cluster with Pulumi)。假设我们有一个 Deployment 与选择器 app=tekton-dashboard(它是 default Tekton dashboard you can deploy as stated in the docs)一起准备好,tekton-dashboard-service.yml 中定义的 LoadBalancer 类型的 Service 可能如下所示:
apiVersion: v1
kind: Service
metadata:
name: tekton-dashboard-external-svc-manual
spec:
selector:
app: tekton-dashboard
ports:
- protocol: TCP
port: 80
targetPort: 9097
type: LoadBalancer
如果我们使用kubectl apply -f tekton-dashboard-service.yml -n tekton-pipelines 在集群中创建服务,AWS ELB 会自动创建:
只有一个问题:.status.loadBalancer 字段异步填充了ingress[0].hostname 字段,因此无法立即使用。如果我们一起运行以下命令,我们可以检查这一点:
kubectl apply -f tekton-dashboard-service.yml -n tekton-pipelines && \
kubectl get service/tekton-dashboard-external-svc-manual -n tekton-pipelines --output=jsonpath='{.status.loadBalancer}'
输出将是一个空字段:
{}%
因此,例如,如果我们想在 CI 管道中运行此设置(例如 GitHub Actions, see the example project's workflow provision.yml),我们需要以某种方式等到 .status.loadBalancer 字段填充 AWS ELB 的主机名。我们如何使用kubectl wait 来实现这一点?
【问题讨论】:
标签: amazon-web-services kubernetes kubectl amazon-eks aws-load-balancer