mirror of
https://github.com/optim-enterprises-bv/kubernetes.git
synced 2025-11-02 11:18:16 +00:00
Merge pull request #31707 from apprenda/windows_infra_container
Automatic merge from submit-queue Initial work on running windows containers on Kubernetes <!-- Thanks for sending a pull request! Here are some tips for you: 1. If this is your first time, read our contributor guidelines https://github.com/kubernetes/kubernetes/blob/master/CONTRIBUTING.md and developer guide https://github.com/kubernetes/kubernetes/blob/master/docs/devel/development.md 2. If you want *faster* PR reviews, read how: https://github.com/kubernetes/kubernetes/blob/master/docs/devel/faster_reviews.md 3. Follow the instructions for writing a release note: https://github.com/kubernetes/kubernetes/blob/master/docs/devel/pull-requests.md#release-notes --> This is the first stab at getting the Kubelet running on Windows (fixes #30279), and getting it to deploy network-accessible pods that consist of Windows containers. Thanks @csrwng, @jbhurat for helping out. The main challenge with Windows containers at this point is that container networking is not supported. In other words, each container in the pod will get it's own IP address. For this reason, we had to make a couple of changes to the kubelet when it comes to setting the pod's IP in the Pod Status. Instead of using the infra-container's IP, we use the IP address of the first container. Other approaches we investigated involved "disabling" the infra container, either conditionally on `runtime.GOOS` or having a separate windows-docker container runtime that re-implemented some of the methods (would require some refactoring to avoid maintainability nightmare). Other changes: - The default docker endpoint was removed. This results in the docker client using the default for the specific underlying OS. More detailed documentation on how to setup the Windows kubelet can be found at https://docs.google.com/document/d/1IjwqpwuRdwcuWXuPSxP-uIz0eoJNfAJ9MWwfY20uH3Q. cc: @ikester @brendandburns @jstarks
This commit is contained in:
@@ -28,6 +28,7 @@ import (
|
||||
"os/exec"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
@@ -58,7 +59,7 @@ import (
|
||||
"k8s.io/kubernetes/pkg/kubelet/types"
|
||||
"k8s.io/kubernetes/pkg/kubelet/util/cache"
|
||||
"k8s.io/kubernetes/pkg/kubelet/util/format"
|
||||
"k8s.io/kubernetes/pkg/runtime"
|
||||
kruntime "k8s.io/kubernetes/pkg/runtime"
|
||||
"k8s.io/kubernetes/pkg/security/apparmor"
|
||||
"k8s.io/kubernetes/pkg/securitycontext"
|
||||
kubetypes "k8s.io/kubernetes/pkg/types"
|
||||
@@ -360,16 +361,7 @@ var (
|
||||
// that the container passed is the infrastructure container of a pod and the responsibility
|
||||
// of the caller to ensure that the correct container is passed.
|
||||
func (dm *DockerManager) determineContainerIP(podNamespace, podName string, container *dockertypes.ContainerJSON) (string, error) {
|
||||
result := ""
|
||||
|
||||
if container.NetworkSettings != nil {
|
||||
result = container.NetworkSettings.IPAddress
|
||||
|
||||
// Fall back to IPv6 address if no IPv4 address is present
|
||||
if result == "" {
|
||||
result = container.NetworkSettings.GlobalIPv6Address
|
||||
}
|
||||
}
|
||||
result := getContainerIP(container)
|
||||
|
||||
networkMode := getDockerNetworkMode(container)
|
||||
isHostNetwork := networkMode == namespaceModeHost
|
||||
@@ -450,7 +442,7 @@ func (dm *DockerManager) inspectContainer(id string, podName, podNamespace strin
|
||||
// Container that are running, restarting and paused
|
||||
status.State = kubecontainer.ContainerStateRunning
|
||||
status.StartedAt = startedAt
|
||||
if containerName == PodInfraContainerName {
|
||||
if containerProvidesPodIP(dockerName) {
|
||||
ip, err = dm.determineContainerIP(podNamespace, podName, iResult)
|
||||
// Kubelet doesn't handle the network error scenario
|
||||
if err != nil {
|
||||
@@ -628,7 +620,7 @@ func (dm *DockerManager) runContainer(
|
||||
// TODO: This is kind of hacky, we should really just encode the bits we need.
|
||||
// TODO: This is hacky because the Kubelet should be parameterized to encode a specific version
|
||||
// and needs to be able to migrate this whenever we deprecate v1. Should be a member of DockerManager.
|
||||
if data, err := runtime.Encode(api.Codecs.LegacyCodec(unversioned.GroupVersion{Group: api.GroupName, Version: "v1"}), pod); err == nil {
|
||||
if data, err := kruntime.Encode(api.Codecs.LegacyCodec(unversioned.GroupVersion{Group: api.GroupName, Version: "v1"}), pod); err == nil {
|
||||
labels[kubernetesPodLabel] = string(data)
|
||||
} else {
|
||||
glog.Errorf("Failed to encode pod: %s for prestop hook", pod.Name)
|
||||
@@ -705,6 +697,12 @@ func (dm *DockerManager) runContainer(
|
||||
SecurityOpt: fmtSecurityOpts,
|
||||
}
|
||||
|
||||
// There is no /etc/resolv.conf in Windows, DNS and DNSSearch options would have to be passed to Docker runtime instead
|
||||
if runtime.GOOS == "windows" {
|
||||
hc.DNS = opts.DNS
|
||||
hc.DNSSearch = opts.DNSSearch
|
||||
}
|
||||
|
||||
// Set sysctls if requested
|
||||
if container.Name == PodInfraContainerName {
|
||||
sysctls, unsafeSysctls, err := api.SysctlsFromPodAnnotations(pod.Annotations)
|
||||
@@ -1154,23 +1152,6 @@ func (dm *DockerManager) fmtDockerOpts(opts []dockerOpt) ([]string, error) {
|
||||
return fmtOpts, nil
|
||||
}
|
||||
|
||||
func (dm *DockerManager) getSecurityOpts(pod *api.Pod, ctrName string) ([]dockerOpt, error) {
|
||||
var securityOpts []dockerOpt
|
||||
if seccompOpts, err := dm.getSeccompOpts(pod, ctrName); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
securityOpts = append(securityOpts, seccompOpts...)
|
||||
}
|
||||
|
||||
if appArmorOpts, err := dm.getAppArmorOpts(pod, ctrName); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
securityOpts = append(securityOpts, appArmorOpts...)
|
||||
}
|
||||
|
||||
return securityOpts, nil
|
||||
}
|
||||
|
||||
type dockerOpt struct {
|
||||
// The key-value pair passed to docker.
|
||||
key, value string
|
||||
@@ -1654,7 +1635,7 @@ func containerAndPodFromLabels(inspect *dockertypes.ContainerJSON) (pod *api.Pod
|
||||
// the pod data may not be set
|
||||
if body, found := labels[kubernetesPodLabel]; found {
|
||||
pod = &api.Pod{}
|
||||
if err = runtime.DecodeInto(api.Codecs.UniversalDecoder(), []byte(body), pod); err == nil {
|
||||
if err = kruntime.DecodeInto(api.Codecs.UniversalDecoder(), []byte(body), pod); err == nil {
|
||||
name := labels[types.KubernetesContainerNameLabel]
|
||||
for ix := range pod.Spec.Containers {
|
||||
if pod.Spec.Containers[ix].Name == name {
|
||||
@@ -2363,7 +2344,14 @@ func (dm *DockerManager) tryContainerStart(container *api.Container, pod *api.Po
|
||||
restartCount = containerStatus.RestartCount + 1
|
||||
}
|
||||
|
||||
_, err = dm.runContainerInPod(pod, container, namespaceMode, namespaceMode, pidMode, podIP, restartCount)
|
||||
// Allow override of networking mode for specific platforms (e.g. Windows)
|
||||
netMode := getNetworkingMode()
|
||||
if netMode == "" {
|
||||
// If not overriden, use the namespace mode
|
||||
netMode = namespaceMode
|
||||
}
|
||||
|
||||
_, err = dm.runContainerInPod(pod, container, netMode, namespaceMode, pidMode, podIP, restartCount)
|
||||
if err != nil {
|
||||
// TODO(bburns) : Perhaps blacklist a container after N failures?
|
||||
return kubecontainer.ErrRunContainer, err.Error()
|
||||
@@ -2660,7 +2648,7 @@ func (dm *DockerManager) GetPodStatus(uid kubetypes.UID, name, namespace string)
|
||||
}
|
||||
}
|
||||
containerStatuses = append(containerStatuses, result)
|
||||
if ip != "" {
|
||||
if containerProvidesPodIP(dockerName) && ip != "" {
|
||||
podStatus.IP = ip
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user