mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-01 07:47:56 +00:00
Add Host field to TCPSocketAction
Currently, TCPSocketAction always uses Pod's IP in connection. But when a pod uses the host network, sometimes firewall rules may prevent kubelet from connecting through the Pod's IP. This PR introduces the 'Host' field for TCPSocketAction, and if it is set to non-empty string, the probe will be performed on the configured host rather than the Pod's IP. This gives users an opportunity to explicitly specify 'localhost' as the target for the above situations.
This commit is contained in:
parent
5e29e1ee05
commit
63f1b077dc
@ -1391,6 +1391,9 @@ type TCPSocketAction struct {
|
||||
// Required: Port to connect to.
|
||||
// +optional
|
||||
Port intstr.IntOrString
|
||||
// Optional: Host name to connect to, defaults to the pod IP.
|
||||
// +optional
|
||||
Host string
|
||||
}
|
||||
|
||||
// ExecAction describes a "run in container" action.
|
||||
|
@ -1492,6 +1492,9 @@ type TCPSocketAction struct {
|
||||
// Number must be in the range 1 to 65535.
|
||||
// Name must be an IANA_SVC_NAME.
|
||||
Port intstr.IntOrString `json:"port" protobuf:"bytes,1,opt,name=port"`
|
||||
// Optional: Host name to connect to, defaults to the pod IP.
|
||||
// +optional
|
||||
Host string `json:"host,omitempty" protobuf:"bytes,2,opt,name=host"`
|
||||
}
|
||||
|
||||
// ExecAction describes a "run in container" action.
|
||||
|
@ -168,8 +168,12 @@ func (pb *prober) runProbe(p *v1.Probe, pod *v1.Pod, status v1.PodStatus, contai
|
||||
if err != nil {
|
||||
return probe.Unknown, "", err
|
||||
}
|
||||
glog.V(4).Infof("TCP-Probe PodIP: %v, Port: %v, Timeout: %v", status.PodIP, port, timeout)
|
||||
return pb.tcp.Probe(status.PodIP, port, timeout)
|
||||
host := p.TCPSocket.Host
|
||||
if host == "" {
|
||||
host = status.PodIP
|
||||
}
|
||||
glog.V(4).Infof("TCP-Probe Host: %v, Port: %v, Timeout: %v", host, port, timeout)
|
||||
return pb.tcp.Probe(host, port, timeout)
|
||||
}
|
||||
glog.Warningf("Failed to find probe builder for container: %v", container)
|
||||
return probe.Unknown, "", fmt.Errorf("Missing probe handler for %s:%s", format.Pod(pod), container.Name)
|
||||
|
@ -1144,7 +1144,7 @@ func DescribeProbe(probe *api.Probe) string {
|
||||
url.Path = probe.HTTPGet.Path
|
||||
return fmt.Sprintf("http-get %s %s", url.String(), attrs)
|
||||
case probe.TCPSocket != nil:
|
||||
return fmt.Sprintf("tcp-socket :%s %s", probe.TCPSocket.Port.String(), attrs)
|
||||
return fmt.Sprintf("tcp-socket %s:%s %s", probe.TCPSocket.Host, probe.TCPSocket.Port.String(), attrs)
|
||||
}
|
||||
return fmt.Sprintf("unknown %s", attrs)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user