问题描述
当我使用以下规范创建Kubernetes负载均衡器服务时:
{
"apiVersion": "v1",
"kind": "Service",
"metadata": {
"name": "a1"
},
"spec": {
"selector": {
"app": "a1"
},
"ports": [
{
"port": 80,
"targetPort": 80,
"name": "http"
},
{
"port": 443,
"targetPort": 443,
"name": "https"
}
],
"type": "LoadBalancer"
}
}
我必须等待1至2分钟,直到得到EXTERNAL_IP
.
我想到了要在服务创建之前保留静态IP并对其进行分配:
{
"apiVersion": "v1",
"kind": "Service",
"metadata": {
"name": "a1"
},
"spec": {
"selector": {
"app": "a1"
},
"ports": [
{
"port": 80,
"targetPort": 80,
"name": "http"
},
{
"port": 443,
"targetPort": 443,
"name": "https"
}
],
"type": "LoadBalancer",
"loadBalancerIP": "130.211.64.237"
}
}
但我也有1-1.5分钟的延迟:
$ kubectl get svc
NAME CLUSTER_IP EXTERNAL_IP PORT(S) SELECTOR AGE
a1 10.127.248.248 130.211.64.237 80/TCP,443/TCP app=a1 1m
有人知道为什么会出现这种延迟吗?是否有办法将其缩短?
不幸的是,延迟是由Compute Engine API中用于创建负载平衡服务的组件的延迟引起的,没有真正的方法来避免它. /p>
在指示创建负载均衡器时,Kubernetes主服务器必须创建一个静态IP地址,一个目标池,一个转发规则和一个防火墙规则.这些资源可能需要花费一些时间才能完全初始化并可以使用,因此现在暂时等待一两分钟.
When I create a Kubernetes Load Balancer Service using the following specification:
{
"apiVersion": "v1",
"kind": "Service",
"metadata": {
"name": "a1"
},
"spec": {
"selector": {
"app": "a1"
},
"ports": [
{
"port": 80,
"targetPort": 80,
"name": "http"
},
{
"port": 443,
"targetPort": 443,
"name": "https"
}
],
"type": "LoadBalancer"
}
}
I have to wait between 1 and 2 minutes until I get an EXTERNAL_IP
.
I thought of reserving static IPs before and assigning them on Service creation:
{
"apiVersion": "v1",
"kind": "Service",
"metadata": {
"name": "a1"
},
"spec": {
"selector": {
"app": "a1"
},
"ports": [
{
"port": 80,
"targetPort": 80,
"name": "http"
},
{
"port": 443,
"targetPort": 443,
"name": "https"
}
],
"type": "LoadBalancer",
"loadBalancerIP": "130.211.64.237"
}
}
But I have the same delay 1 - 1.5 minutes:
$ kubectl get svc
NAME CLUSTER_IP EXTERNAL_IP PORT(S) SELECTOR AGE
a1 10.127.248.248 130.211.64.237 80/TCP,443/TCP app=a1 1m
Does anyone know why this delay happens and if there is a way to shorten it?
The delay is unfortunately just caused by latency in the Compute Engine APIs for creating the components of a load balanced service, and there's no real way to avoid it.
The Kubernetes master, when instructed to create a load balancer, has to create a static IP address, a target pool, a forwarding rule, and a firewall rule. These resources can take some time to fully initialize and be ready for use, so a wait of a minute or two is to be expected for now.
这篇关于缓慢的静态IP分配给Google Cloud Platform上的Kubernetes负载均衡器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!