mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-26 21:17:23 +00:00
Fix network configuration
This commit is contained in:
parent
4a386f881f
commit
c341cee65b
@ -643,15 +643,6 @@ func (dm *DockerManager) runContainer(
|
|||||||
PodUID: pod.UID,
|
PodUID: pod.UID,
|
||||||
ContainerName: container.Name,
|
ContainerName: container.Name,
|
||||||
}
|
}
|
||||||
exposedPorts, portBindings := makePortsAndBindings(opts.PortMappings)
|
|
||||||
|
|
||||||
// TODO(vmarmol): Handle better.
|
|
||||||
// Cap hostname at 63 chars (specification is 64bytes which is 63 chars and the null terminating char).
|
|
||||||
const hostnameMaxLen = 63
|
|
||||||
containerHostname := pod.Name
|
|
||||||
if len(containerHostname) > hostnameMaxLen {
|
|
||||||
containerHostname = containerHostname[:hostnameMaxLen]
|
|
||||||
}
|
|
||||||
|
|
||||||
// Pod information is recorded on the container as labels to preserve it in the event the pod is deleted
|
// Pod information is recorded on the container as labels to preserve it in the event the pod is deleted
|
||||||
// while the Kubelet is down and there is no information available to recover the pod.
|
// while the Kubelet is down and there is no information available to recover the pod.
|
||||||
@ -707,13 +698,13 @@ func (dm *DockerManager) runContainer(
|
|||||||
binds = append(binds, b)
|
binds = append(binds, b)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
hc := &docker.HostConfig{
|
hc := &docker.HostConfig{
|
||||||
PortBindings: portBindings,
|
Binds: binds,
|
||||||
Binds: binds,
|
NetworkMode: netMode,
|
||||||
NetworkMode: netMode,
|
IpcMode: ipcMode,
|
||||||
IpcMode: ipcMode,
|
UTSMode: utsMode,
|
||||||
UTSMode: utsMode,
|
PidMode: pidMode,
|
||||||
PidMode: pidMode,
|
|
||||||
// Memory and CPU are set here for newer versions of Docker (1.6+).
|
// Memory and CPU are set here for newer versions of Docker (1.6+).
|
||||||
Memory: memoryLimit,
|
Memory: memoryLimit,
|
||||||
MemorySwap: -1,
|
MemorySwap: -1,
|
||||||
@ -728,12 +719,6 @@ func (dm *DockerManager) runContainer(
|
|||||||
hc.CPUPeriod = cpuPeriod
|
hc.CPUPeriod = cpuPeriod
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(opts.DNS) > 0 {
|
|
||||||
hc.DNS = opts.DNS
|
|
||||||
}
|
|
||||||
if len(opts.DNSSearch) > 0 {
|
|
||||||
hc.DNSSearch = opts.DNSSearch
|
|
||||||
}
|
|
||||||
if len(opts.CgroupParent) > 0 {
|
if len(opts.CgroupParent) > 0 {
|
||||||
hc.CgroupParent = opts.CgroupParent
|
hc.CgroupParent = opts.CgroupParent
|
||||||
}
|
}
|
||||||
@ -741,10 +726,8 @@ func (dm *DockerManager) runContainer(
|
|||||||
dockerOpts := docker.CreateContainerOptions{
|
dockerOpts := docker.CreateContainerOptions{
|
||||||
Name: containerName,
|
Name: containerName,
|
||||||
Config: &docker.Config{
|
Config: &docker.Config{
|
||||||
Env: makeEnvList(opts.Envs),
|
Env: makeEnvList(opts.Envs),
|
||||||
ExposedPorts: exposedPorts,
|
Image: container.Image,
|
||||||
Hostname: containerHostname,
|
|
||||||
Image: container.Image,
|
|
||||||
// Memory and CPU are set here for older versions of Docker (pre-1.6).
|
// Memory and CPU are set here for older versions of Docker (pre-1.6).
|
||||||
Memory: memoryLimit,
|
Memory: memoryLimit,
|
||||||
MemorySwap: -1,
|
MemorySwap: -1,
|
||||||
@ -759,6 +742,11 @@ func (dm *DockerManager) runContainer(
|
|||||||
HostConfig: hc,
|
HostConfig: hc,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set network configuration for infra-container
|
||||||
|
if container.Name == PodInfraContainerName {
|
||||||
|
setInfraContainerNetworkConfig(pod, netMode, opts, dockerOpts)
|
||||||
|
}
|
||||||
|
|
||||||
setEntrypointAndCommand(container, opts, &dockerOpts)
|
setEntrypointAndCommand(container, opts, &dockerOpts)
|
||||||
|
|
||||||
glog.V(3).Infof("Container %v/%v/%v: setting entrypoint \"%v\" and command \"%v\"", pod.Namespace, pod.Name, container.Name, dockerOpts.Config.Entrypoint, dockerOpts.Config.Cmd)
|
glog.V(3).Infof("Container %v/%v/%v: setting entrypoint \"%v\" and command \"%v\"", pod.Namespace, pod.Name, container.Name, dockerOpts.Config.Entrypoint, dockerOpts.Config.Cmd)
|
||||||
@ -783,6 +771,31 @@ func (dm *DockerManager) runContainer(
|
|||||||
return kubecontainer.DockerID(dockerContainer.ID).ContainerID(), nil
|
return kubecontainer.DockerID(dockerContainer.ID).ContainerID(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// setInfraContainerNetworkConfig sets the network configuration for the infra-container. We only set network configuration for infra-container, all
|
||||||
|
// the user containers will share the same network namespace with infra-container.
|
||||||
|
func setInfraContainerNetworkConfig(pod *api.Pod, netMode string, opts *kubecontainer.RunContainerOptions, dockerOpts docker.CreateContainerOptions) {
|
||||||
|
exposedPorts, portBindings := makePortsAndBindings(opts.PortMappings)
|
||||||
|
dockerOpts.Config.ExposedPorts = exposedPorts
|
||||||
|
dockerOpts.HostConfig.PortBindings = portBindings
|
||||||
|
|
||||||
|
if netMode != namespaceModeHost {
|
||||||
|
// TODO(vmarmol): Handle better.
|
||||||
|
// Cap hostname at 63 chars (specification is 64bytes which is 63 chars and the null terminating char).
|
||||||
|
const hostnameMaxLen = 63
|
||||||
|
containerHostname := pod.Name
|
||||||
|
if len(containerHostname) > hostnameMaxLen {
|
||||||
|
containerHostname = containerHostname[:hostnameMaxLen]
|
||||||
|
}
|
||||||
|
dockerOpts.Config.Hostname = containerHostname
|
||||||
|
if len(opts.DNS) > 0 {
|
||||||
|
dockerOpts.HostConfig.DNS = opts.DNS
|
||||||
|
}
|
||||||
|
if len(opts.DNSSearch) > 0 {
|
||||||
|
dockerOpts.HostConfig.DNSSearch = opts.DNSSearch
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func setEntrypointAndCommand(container *api.Container, opts *kubecontainer.RunContainerOptions, dockerOpts *docker.CreateContainerOptions) {
|
func setEntrypointAndCommand(container *api.Container, opts *kubecontainer.RunContainerOptions, dockerOpts *docker.CreateContainerOptions) {
|
||||||
command, args := kubecontainer.ExpandContainerCommandAndArgs(container, opts.Envs)
|
command, args := kubecontainer.ExpandContainerCommandAndArgs(container, opts.Envs)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user