gg297231604 2021-12-29 21:21 采纳率: 100%
浏览 134
已结题

kubernetes 安装了weave,但创建pod仍然报网络错误,如何解决?

刚学习k8s, 创建了集群,安装了Weave Net容器网络插件,集群状态如下:

[sgguo@k8s-master ~]$ kubectl -n kube-system get pod
NAME                                 READY   STATUS    RESTARTS      AGE
etcd-k8s-master                      1/1     Running   3 (22m ago)   3d
kube-apiserver-k8s-master            1/1     Running   3 (22m ago)   3d
kube-controller-manager-k8s-master   1/1     Running   4 (22m ago)   3d
kube-proxy-gxxxj                     1/1     Running   3 (22m ago)   3d
kube-proxy-ms4wd                     1/1     Running   3 (21m ago)   3d
kube-proxy-p2gt2                     1/1     Running   2 (21m ago)   2d
kube-scheduler-k8s-master            1/1     Running   4 (22m ago)   3d
weave-net-7mmlq                      2/2     Running   6 (22m ago)   3d
weave-net-8ml2g                      2/2     Running   6 (21m ago)   3d
weave-net-fkxq5                      2/2     Running   4 (21m ago)   2d
[sgguo@k8s-master ~]$ kubectl -n kube-system get node
NAME         STATUS   ROLES                  AGE   VERSION
k8s-master   Ready    control-plane,master   3d    v1.23.1
k8s-node1    Ready    <none>                 3d    v1.23.1
k8s-node2    Ready    <none>                 2d    v1.23.1

按照官方示例创建 Redis Deployment:

# SOURCE: https://cloud.google.com/kubernetes-engine/docs/tutorials/guestbook
apiVersion: apps/v1
kind: Deployment
metadata:
  name: redis-leader
  labels:
    app: redis
    role: leader
    tier: backend
spec:
  replicas: 1
  selector:
    matchLabels:
      app: redis
  template:
    metadata:
      labels:
        app: redis
        role: leader
        tier: backend
    spec:
      containers:
      - name: leader
        image: "docker.io/redis:6.0.5"
        resources:
          requests:
            cpu: 100m
            memory: 100Mi
        ports:
        - containerPort: 6379



但是pod起不来,情况如下:

[sgguo@k8s-master guestbook]$ kubectl get pod
NAME                            READY   STATUS              RESTARTS   AGE
redis-leader-766465cd9c-jqt8g   0/1     ContainerCreating   0          9s
[sgguo@k8s-master guestbook]$ kubectl describe  pod redis-leader-766465cd9c-jqt8g
Name:           redis-leader-766465cd9c-jqt8g
Namespace:      default
Priority:       0
Node:           k8s-node1/192.168.31.161
Start Time:     Wed, 29 Dec 2021 20:52:02 +0800
Labels:         app=redis
                pod-template-hash=766465cd9c
                role=leader
                tier=backend
Annotations:    <none>
Status:         Pending
IP:
IPs:            <none>
Controlled By:  ReplicaSet/redis-leader-766465cd9c
Containers:
  leader:
    Container ID:
    Image:          docker.io/redis:6.0.5
    Image ID:
    Port:           6379/TCP
    Host Port:      0/TCP
    State:          Waiting
      Reason:       ContainerCreating
    Ready:          False
    Restart Count:  0
    Requests:
      cpu:        100m
      memory:     100Mi
    Environment:  <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-nbk4n (ro)
Conditions:
  Type              Status
  Initialized       True
  Ready             False
  ContainersReady   False
  PodScheduled      True
Volumes:
  kube-api-access-nbk4n:
    Type:                    Projected (a volume that contains injected data from multiple sources)
    TokenExpirationSeconds:  3607
    ConfigMapName:           kube-root-ca.crt
    ConfigMapOptional:       <nil>
    DownwardAPI:             true
QoS Class:                   Burstable
Node-Selectors:              <none>
Tolerations:                 node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
                             node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:
  Type     Reason                  Age                 From               Message
  ----     ------                  ----                ----               -------
  Normal   Scheduled               28s                 default-scheduler  Successfully assigned default/redis-leader-766465cd9c-jqt8g to k8s-node1
  Warning  FailedCreatePodSandBox  27s                 kubelet            Failed to create pod sandbox: rpc error: code = Unknown desc = failed to set up sandbox container "c8d9e6786d33cb5520ca2d6d62304a0bc716a84f019e9fa681bcc777b18f924e" network for pod "redis-leader-766465cd9c-jqt8g": networkPlugin cni failed to set up pod "redis-leader-766465cd9c-jqt8g_default" network: open /run/flannel/subnet.env: no such file or directory
  Warning  FailedCreatePodSandBox  26s                 kubelet            Failed to create pod sandbox: rpc error: code = Unknown desc = failed to set up sandbox container "f7c457209f92ff179e89e89da608424dbecc7d906effdfc150e35e3953ad5547" network for pod "redis-leader-766465cd9c-jqt8g": networkPlugin cni failed to set up pod "redis-leader-766465cd9c-jqt8g_default" network: open /run/flannel/subnet.env: no such file or directory
  Warning  FailedCreatePodSandBox  25s                 kubelet            Failed to create pod sandbox: rpc error: code = Unknown desc = failed to set up sandbox container "82d7f53eb9c4c267abe928cf1d7c9ebe305fdd10ae321b071f07636d2d53e38e" network for pod "redis-leader-766465cd9c-jqt8g": networkPlugin cni failed to set up pod "redis-leader-766465cd9c-jqt8g_default" network: open /run/flannel/subnet.env: no such file or directory
  Warning  FailedCreatePodSandBox  24s                 kubelet            Failed to create pod sandbox: rpc error: code = Unknown desc = failed to set up sandbox container "0f3aab97eda79a1f459ab5d0c7873929230dfadf722d5a5162d6429e91b40132" network for pod "redis-leader-766465cd9c-jqt8g": networkPlugin cni failed to set up pod "redis-leader-766465cd9c-jqt8g_default" network: open /run/flannel/subnet.env: no such file or directory
  Warning  FailedCreatePodSandBox  22s                 kubelet            Failed to create pod sandbox: rpc error: code = Unknown desc = failed to set up sandbox container "e2c9142fbc24ef2f55f78de9d7e31ed387d1d385338efa5022157fa78b324a90" network for pod "redis-leader-766465cd9c-jqt8g": networkPlugin cni failed to set up pod "redis-leader-766465cd9c-jqt8g_default" network: open /run/flannel/subnet.env: no such file or directory
  Warning  FailedCreatePodSandBox  21s                 kubelet            Failed to create pod sandbox: rpc error: code = Unknown desc = failed to set up sandbox container "4d57eecfc2cb78fe4cf9979225fe22faf500b82e53e3453f6eddd894474d6e2c" network for pod "redis-leader-766465cd9c-jqt8g": networkPlugin cni failed to set up pod "redis-leader-766465cd9c-jqt8g_default" network: open /run/flannel/subnet.env: no such file or directory
  Warning  FailedCreatePodSandBox  20s                 kubelet            Failed to create pod sandbox: rpc error: code = Unknown desc = failed to set up sandbox container "7f067604a4ddcee7bea960a537e1f454b57fdec671c222e87a999b30ad09d629" network for pod "redis-leader-766465cd9c-jqt8g": networkPlugin cni failed to set up pod "redis-leader-766465cd9c-jqt8g_default" network: open /run/flannel/subnet.env: no such file or directory
  Warning  FailedCreatePodSandBox  18s                 kubelet            Failed to create pod sandbox: rpc error: code = Unknown desc = failed to set up sandbox container "6262368bdea4b2d17954a90de325a9f4f6385ac170f8050b242fb13c73d31349" network for pod "redis-leader-766465cd9c-jqt8g": networkPlugin cni failed to set up pod "redis-leader-766465cd9c-jqt8g_default" network: open /run/flannel/subnet.env: no such file or directory
  Warning  FailedCreatePodSandBox  16s                 kubelet            Failed to create pod sandbox: rpc error: code = Unknown desc = failed to set up sandbox container "ce4978c4d5b5dd4641aa46a23beea81d15efd0d7c46941d53d44e1db0623bb1f" network for pod "redis-leader-766465cd9c-jqt8g": networkPlugin cni failed to set up pod "redis-leader-766465cd9c-jqt8g_default" network: open /run/flannel/subnet.env: no such file or directory
  Normal   SandboxChanged          13s (x12 over 26s)  kubelet            Pod sandbox changed, it will be killed and re-created.
  Warning  FailedCreatePodSandBox  12s (x4 over 15s)   kubelet            (combined from similar events): Failed to create pod sandbox: rpc error: code = Unknown desc = failed to set up sandbox container "9c20e804eb1f748b3a0d49c2cc9f784a1a088a5a87b88423a12d146bc2f75d45" network for pod "redis-leader-766465cd9c-jqt8g": networkPlugin cni failed to set up pod "redis-leader-766465cd9c-jqt8g_default" network: open /run/flannel/subnet.env: no such file or directory

看起来pod要使用flannel,而我没有安装这个插件。
不明白的是已经有weave了,为什么要去使用flannel?是有什么地方需要配置么?

  • 写回答

2条回答 默认 最新

  • 闻志流e师兄 2021-12-31 15:04
    关注

    kubelet启动时需要指定--network-plugin=xxx,在pod创建阶段,初始化网络时会根据这个去配置网络。具体原理你自己去查。
    你初始化集群时肯定指定的网络是flannel,那么你在添加node时它自动生成的这个对应的也是flannel
    具体你可以检查node上/etc/cni/net.d这个目录下的配置文件。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 1月17日
  • 已采纳回答 1月9日
  • 创建了问题 12月29日

悬赏问题

  • ¥15 Bibtex4Word 引用中文文献
  • ¥20 用opencv c/c++ 转换成灰度图,然后做一下直方图均衡,输出mp4文件
  • ¥20 matlab中的双层数值积分
  • ¥50 服务器打印水晶报表问题
  • ¥30 gradle环境下javafx项目如何使用druid连接池
  • ¥15 服务器打印水晶报表问题
  • ¥18 深度学习tensorflow1,ssdv1,coco数据集训练一个模型
  • ¥100 关于注册表摄像头和麦克风的问题
  • ¥30 代码本地运行正常,但是TOMCAT部署时闪退
  • ¥15 关于#python#的问题