“kube-flannel.yml“: daemonsets.apps “kube-flannel-ds“ already exists

在尝试部署kube-flannel.yml时遇到了错误,服务器返回已存在(AlreadyExists)的错误,包括PodSecurityPolicies、ClusterRoles、ClusterRoleBindings、ServiceAccounts、ConfigMaps和DaemonSets。为了解决这个问题,需要先删除现有资源,使用`kubectl delete -f kube-flannel.yml`,然后再尝试创建,使用`kubectl create -f kube-flannel.yml`。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Error from server (AlreadyExists): error when creating “kube-flannel.yml”: podsecuritypolicies.policy “psp.flannel.unprivileged” already exists
Error from server (AlreadyExists): error when creating “kube-flannel.yml”: clusterroles.rbac.authorization.k8s.io “flannel” already exists
Error from server (AlreadyExists): error when creating “kube-flannel.yml”: clusterrolebindings.rbac.authorization.k8s.io “flannel” already exists
Error from server (AlreadyExists): error when creating “kube-flannel.yml”: serviceaccounts “flannel” already exists
Error from server (AlreadyExists): error when creating “kube-flannel.yml”: configmaps “kube-flannel-cfg” already exists
Error from server (AlreadyExists): error when creating “kube-flannel.yml”: daemonsets.apps “kube-flannel-ds” already exists

kube-flannel存在

需要先删除
kubectl delete -f kube-flannel.yml
在创建
kubectl create -f kube-flannel.yml

### 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、付费专栏及课程。

余额充值