【问题标题】:kubernetes specified host networking, but is disallowed?kubernetes 指定主机网络,但不允许?
【发布时间】:2016-02-02 09:15:33
【问题描述】:

我遇到了这个问题。 这个问题可以通过以下步骤重现。

重播此问题的方法。 在开始之前,我以这种模式运行 docker

/usr/bin/docker -d -H fd:// --iptables=false

首先 运行 etcd,我在 docker 容器上运行 etcd。

docker run --net=host -d gcr.io/google_containers/etcd:2.0.12 /usr/local/bin/etcd --addr=yourHostIp:4001 --bind-addr=0.0.0.0:4001 --data-dir=/var/etcd/data

其次

docker pull gcr.io/google_containers/hyperkube:v1.0.1

通过 docker run 运行容器: 在容器中安装 vim 后,我将文件 /etc/kubernetes/manifests/master.json 更改如下:

{
"apiVersion": "v1",
"kind": "Pod",
"metadata": {"name":"k8s-master"},
"spec":{
  "hostNetwork": true,
  "containers":[
    {
      "name": "controller-manager",
      "image": "gcr.io/google_containers/hyperkube:self-1.0.1",
      "command": [
              "/hyperkube",
              "controller-manager",
              "--master=yourHostIp:8080",
              "--v=2"
        ]
    },
    {
      "name": "apiserver",
      "image": "gcr.io/google_containers/hyperkube:self-1.0.1",
      "command": [
              "/hyperkube",
              "apiserver",
              "--portal-net=10.0.0.1/24",
              "--address=yourHostIp",
              "--etcd_servers=http://yourHostIp:4001",
              "--cluster_name=kubernetes",
              "--v=2"
        ]
    },
    {
      "name": "scheduler",
      "image": "gcr.io/google_containers/hyperkube:self-1.0.1",
      "command": [
              "/hyperkube",
              "scheduler",
              "--master=yourHostIp:8080",
              "--v=2"
        ]
    }
  ]
 }
}

然后我将这个更改的容器保存为 gcr.io/google_containers/hyperkube:self-1.0.1

第三: 然后我通过以下命令运行更改后的图像

docker run \
    --volume=/:/rootfs:ro \
    --volume=/sys:/sys:ro \
    --volume=/dev:/dev \
    --volume=/var/lib/docker/:/var/lib/docker:ro \
    --volume=/var/lib/kubelet/:/var/lib/kubelet:rw \
    --volume=/var/run:/var/run:rw \
    --net=host --pid=host --privileged=true -d \
    gcr.io/google_containers/hyperkube:self-1.0.1 \
    /hyperkube kubelet --containerized --hostname-override="10.4.28.51" --address="0.0.0.0" --api-servers=http://yourHostIp:8080 --allow-privileged=true --config=/etc/kubernetes/manifests

最后

{
"apiVersion": "v1",
"kind": "Pod",
"metadata": {"name":"redis-master"},
"spec":{
  "hostNetwork": true,
  "containers":[
    {
      "name": "redis-test",
      "image": "redis:2.8"
    }
  ]
 }
}

通过以上文件创建 pod

kubectrl create -f example.json

当你运行时

kubectl get pod

你应该找到这个: 而且我很奇怪为什么 k8s-master-yourHostIp 的 pod 运行正常。

NAME                    READY     STATUS                                             RESTARTS   AGE
k8s-master-yourHostIp   3/3       Running                                            0          1h
redis-master            0/1       Image: redis:2.8 is ready, container is creating   0          6s

当你尝试时

kubectl -s $(hn):8080 describe pod redis-master

你应该找到

root@XXX:~/kubernetes/examples/redis# kubectl -s $(hn):8080 describe pod redis-master
Name:               redis-master
Namespace:          default
Image(s):           redis:2.8
Node:               yourHostIp/yourHostIp
Start Time:         Tue, 08 Dec 2015 11:59:06 +0800
Labels:             <none>
Status:             Pending
Reason:
Message:
IP:             yourHostIp
Replication Controllers:    <none>
Containers:
  redis-test:
    Container ID:
    Image:      redis:2.8
    Image ID:
    State:      Waiting
      Reason:       Image: redis:2.8 is ready, container is creating
    Ready:      False
    Restart Count:  0
    Environment Variables:
Conditions:
  Type      Status
  Ready     False
No volumes.
Events:
  FirstSeen LastSeen    Count   From            SubobjectPath   Reason      Message
  ───────── ────────    ─────   ────            ─────────────   ──────      ───────
  5m        5m      1   {scheduler }                scheduled   Successfully assigned redis-master to yourHostIp
  5m        8s      34  {kubelet yourHostIp}            failedSync  Error syncing pod, skipping: pod with UID "06b96a71-9d60-11e5-ae3c-008cfaeeacb2" specified host networking, but is disallowed

那我有什么误解吗?

【问题讨论】:

    标签: kubernetes


    【解决方案1】:

    添加以下 kubelet 标志: --host-network-sources="*"

    这是 Kubernetes 1.1 及更高版本中的默认设置。如果可以的话,我建议更新到 1.1.7。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-01-23
      • 1970-01-01
      • 2020-10-06
      • 2022-01-13
      • 2016-02-20
      • 2021-02-15
      • 1970-01-01
      • 2019-01-21
      相关资源
      最近更新 更多