Kubernetes ServiceSpec SessionAffinity 会话保持
程序员文章站
2022-04-20 20:06:00
...
Service 回话亲和力
选项SessionAffinity可选项
Spec: apiv1.ServiceSpec{
SessionAffinity: "",
},
代码注释段 必选项ClientIP 和 None,默认是None,通过ClientIP来保持回话
// Supports "ClientIP" and "None". Used to maintain session affinity.
// Enable client IP based session affinity.
// Must be ClientIP or None.
// Defaults to None.
// More info: https://kubernetes.io/docs/concepts/services-networking/service/#virtual-ips-and-service-proxies
// +optional
SessionAffinity ServiceAffinity `json:"sessionAffinity,omitempty" protobuf:"bytes,7,opt,name=sessionAffinity,casttype=ServiceAffinity"`
代码段 ClientIP 基于客户端地址来实现 None不做回话保持
// Session Affinity Type string
type ServiceAffinity string
const (
// ServiceAffinityClientIP is the Client IP based.
ServiceAffinityClientIP ServiceAffinity = "ClientIP"
// ServiceAffinityNone - no session affinity.
ServiceAffinityNone ServiceAffinity = "None"
)
SessionAffinityConfig 回话保持配置段
Spec: apiv1.ServiceSpec{
SessionAffinity: "",
SessionAffinityConfig: "",
},
SessionAffinityConfig 回话保持配置
# 可选项 配置了基于ClientIP 会话保持
type SessionAffinityConfig struct {
// clientIP contains the configurations of Client IP based session affinity.
// +optional
ClientIP *ClientIPConfig `json:"clientIP,omitempty" protobuf:"bytes,1,opt,name=clientIP"`
}
##配置回话保持时间 范围(0秒 ~ 1天),默认是保持3个小时
// ClientIPConfig represents the configurations of Client IP based session affinity.
type ClientIPConfig struct {
// timeoutSeconds specifies the seconds of ClientIP type session sticky time.
// The value must be >0 && <=86400(for 1 day) if ServiceAffinity == "ClientIP".
// Default value is 10800(for 3 hours).
// +optional
TimeoutSeconds *int32 `json:"timeoutSeconds,omitempty" protobuf:"varint,1,opt,name=timeoutSeconds"`
}