k8s部署flannel时报failed to find plugin “portmap“ in path [/opt/cni/bin]]

现象

# 部署好flannel后,部署coredns,报错,检查/opt/cni/bin目录下,发现没有文件
	Failed to create pod sandbox: rpc error: code = Unknown desc = [failed to set up sandbox container "3bf7500d12ae67983dcd2795d2feb168dceb563ac78afa5508d973db84ed5b47" network for pod "coredns-6f4c9cb7c5-jg5mj": networkPlugin cni failed to set up pod "coredns-6f4c9cb7c5-jg5mj_kube-system" network: failed to find plugin "loopback" in path [/opt/cni/bin], failed to clean up sandbox container "3bf7500d12ae67983dcd2795d2feb168dceb563ac78afa5508d973db84ed5b47" network for pod "coredns-6f4c9cb7c5-jg5mj": networkPlugin cni failed to teardown pod "coredns-6f4c9cb7c5-jg5mj_kube-system" network: failed to find plugin "portmap" in path [/opt/cni/bin]]

# kubelet 日志
	Unable to update cni config: no valid networks found in /etc/cni/net.d

方法一

# 解决办法
cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=0
repo_gpgcheck=0
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF

# 安装软件,存在BUG:这个会自己下载kubelet,对于二进制安装的K8S来说不可能用这种方法,且卸载的时候还会卸掉一些自己配置的东西
	yum clean all && yum makecache && yum -y install kubernetes-cni

方法二

# 解决办法

# 下载cni插件,下载后解压到/opt/cni/bin之后kubelet,然后重新部署flannel和coredns
	https://github.com/containernetworking/plugins/releases
### Kube-flannel.yml Configuration for Kubelet Version 1.23 For Kubernetes clusters running with kubelet version 1.23, the `kube-flannel.yml` file needs to be compatible and properly configured to ensure network functionality within the cluster[^1]. Below is a suitable configuration example tailored specifically for this version: ```yaml apiVersion: policy/v1beta1 kind: PodSecurityPolicy metadata: name: psp.flannel.unprivileged annotations: seccomp.security.alpha.kubernetes.io/allowedProfileNames: docker/default apparmor.security.beta.kubernetes.io/allowedProfiles: runtime/default spec: privileged: false volumes: - emptyDir - hostPath allowedHostPaths: - pathPrefix: "/etc/cni/net.d" - pathPrefix: "/opt/cni/bin" - pathPrefix: "/var/lib/kubelet/pods" - pathPrefix: "/var/lib/kubelet/plugins" - pathPrefix: "/run/flannel" readOnlyRootFilesystem: false --- apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole metadata: name: flannel rules: - apiGroups: [""] resources: ["pods"] verbs: ["get"] - apiGroups: [""] resources: ["nodes"] verbs: ["list", "watch"] - apiGroups: [""] resources: ["nodes/status"] verbs: ["patch"] --- kind: ClusterRoleBinding apiVersion: rbac.authorization.k8s.io/v1 metadata: name: flannel roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole name: flannel subjects: - kind: ServiceAccount name: flannel namespace: kube-system --- apiVersion: v1 kind: ServiceAccount metadata: name: flannel namespace: kube-system --- kind: ConfigMap apiVersion: v1 metadata: name: kube-flannel-cfg namespace: kube-system data: cni-conf.json: | { "name": "cbr0", "plugins": [ { "type": "flannel", "delegate": { "hairpinMode": true, "isDefaultGateway": true } }, { "type": "portmap", "capabilities": { "portMappings": true } } ] } net-conf.json: | { "Network": "10.244.0.0/16", "Backend": { "Type": "vxlan" } } --- apiVersion: apps/v1 kind: DaemonSet metadata: name: kube-flannel-ds namespace: kube-system labels: tier: node app: flannel spec: selector: matchLabels: app: flannel template: metadata: labels: tier: node app: flannel spec: affinity: nodeAffinity: requiredDuringSchedulingIgnoredDuringExecution: nodeSelectorTerms: - matchExpressions: - key: kubernetes.io/os operator: In values: - linux tolerations: - effect: NoSchedule operator: Exists - effect: PreferNoSchedule operator: Exists - effect: NoExecute operator: Exists serviceAccountName: flannel initContainers: - name: install-cni-plugin image: quay.io/kubernetes-network-policy-controller/calico-cni-plugin:v3.20.1 command: - /install-cni.sh env: - name: CNI_CONF_NAME value: "10-flannel.conflist" - name: CNI_NET_DIR value: /host/opt/cni/net.d - name: CNI_BIN_DIR value: /host/opt/cni/bin volumeMounts: - mountPath: /rootfs/etc/cni/net.d/ name: cni-net-dir-host-rootfs - mountPath: /rootfs/opt/cni/bin/ name: cni-bin-dir-host-rootfs - mountPath: /opt/cni/bin name: cni-bin-dir - mountPath: /etc/cni/net.d name: cni-net-dir containers: - name: kube-flannel image: quay.io/coreos/flannel:v0.19.0-amd64 command: - /opt/bin/flanneld - --ip-masq - --kube-subnet-mgr securityContext: capabilities: add: ["NET_ADMIN", "NET_RAW"] env: - name: POD_NAME valueFrom: fieldRef: fieldPath: metadata.name - name: POD_NAMESPACE valueFrom: fieldRef: fieldPath: metadata.namespace volumeMounts: - name: run mountPath: /run/flannel - name: etc-kubernetes mountPath: /etc/kubernetes - name: xtables-lock mountPath: /run/xtables.lock subPath: xtables.lock volumes: - name: run hostPath: path: /run/flannel - name: etc-kubernetes hostPath: path: /etc/kubernetes - name: xtables-lock hostPath: path: /run/xtables.lock - name: cni-bin-dir-host-rootfs hostPath: path: /host/opt/cni/bin - name: cni-net-dir-host-rootfs hostPath: path: /host/etc/cni/net.d - name: cni-bin-dir hostPath: path: /opt/cni/bin - name: cni-net-dir hostPath: path: /etc/cni/net.d ``` This configuration ensures that Flannel operates correctly on nodes where kubelet runs at version 1.23.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

旺仔_牛奶

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值