kubernetes/minikube

Make the kubelet hostPort feature usable by default

Open

#3,056 创建于 2018年8月8日

在 GitHub 查看
 (12 评论) (2 反应) (0 负责人)Go (31,799 star) (5,222 fork)batch import
area/cnihelp wantedkind/featurelifecycle/frozenpriority/backlog

描述

Is this a BUG REPORT or FEATURE REQUEST? (choose one): FEATURE REQUEST

Please provide the following details:

Environment: Debian stretch

Minikube version (use minikube version): v0.28.0

  • OS (e.g. from /etc/os-release): Debian GNU/Linux 9 (stretch)
  • VM Driver (e.g. cat ~/.minikube/machines/minikube/config.json | grep DriverName): kvm2
  • ISO version (e.g. cat ~/.minikube/machines/minikube/config.json | grep -i ISO or minikube ssh cat /etc/VERSION):
  • Install tools: v0.28.0
  • Others:

What happened: I'm enabling cni plugins for minikube by using the following command: minikube start --vm-driver kvm2 --network-plugin=cni --extra-config=kubelet.network-plugin=cni --extra-config=kubelet.cni-conf-dir=/etc/cni/net.d --extra-config=kubelet.cni-bin-dir=/opt/cni/bin

I then want to use a pod with a hostPort, to access the pod easily from inside and outside the minikube VM. Unfortunatly, the default cni conf file doesn't enable the "portmap" cni plugin, which enable the hostport feature. So by default, when using cni plugins, a pod can't be accessed through a hostPort, even if it is configured.

What you expected to happen: I expect the hostPort feature to work by default.

Anything else do we need to know:

Since the portmap cni plugin is available in the minikube VM, at /opt/cni/bin, having the hostport feature enabled by default is just a matter of cni configuration file.

I removed the default /etc/cni/net.d/k8s.conf and added the file /etc/cni/net.d/10-k8s-portmap.conflist with the following content:

{
    "cniVersion": "0.3.1",
    "name": "rkt.kubernetes.io",
    "plugins": [
        {
            "type": "bridge",
            "bridge": "mybridge",
            "mtu": 1460,
            "addIf": "true",
            "isGateway": true,
            "ipMasq": true,
            "ipam": {
                "type": "host-local",
                "subnet": "10.1.0.0/16",
                "gateway": "10.1.0.1",
                "routes": [
                    {
                        "dst": "0.0.0.0/0"
                    }
                ]
            }
        },
        {
            "type": "portmap",
            "capabilities": {"portMappings": true},
            "externalSetMarkChain": "KUBE-MARK-MASQ"
        }
    ]
}

After restarting kubelet, a pod with hostPort enabled is accessible through minikube_ip:hostport, as expected.

贡献者指南