k8s之Flannel网络插件安装提示forbidden无权限

news2024/9/27 5:44:17

在这里插入图片描述

一、问题描述

在安装k8s的网络插件时,提示如下信息,各种forbidden无权限

[root@zzyk8s01 scripts]# kubectl apply -f kube-flannel.yml 
Error from server (Forbidden): error when retrieving current configuration of:
Resource: "policy/v1beta1, Resource=podsecuritypolicies", GroupVersionKind: "policy/v1beta1, Kind=PodSecurityPolicy"
Name: "psp.flannel.unprivileged", Namespace: ""
from server for: "kube-flannel.yml": podsecuritypolicies.policy "psp.flannel.unprivileged" is forbidden: User "system:node:zzyk8s01" cannot get resource "podsecuritypolicies" in API group "policy" at the cluster scope
Error from server (Forbidden): error when retrieving current configuration of:
Resource: "rbac.authorization.k8s.io/v1, Resource=clusterroles", GroupVersionKind: "rbac.authorization.k8s.io/v1, Kind=ClusterRole"
Name: "flannel", Namespace: ""
from server for: "kube-flannel.yml": clusterroles.rbac.authorization.k8s.io "flannel" is forbidden: User "system:node:zzyk8s01" cannot get resource "clusterroles" in API group "rbac.authorization.k8s.io" at the cluster scope
Error from server (Forbidden): error when retrieving current configuration of:
Resource: "rbac.authorization.k8s.io/v1, Resource=clusterrolebindings", GroupVersionKind: "rbac.authorization.k8s.io/v1, Kind=ClusterRoleBinding"
Name: "flannel", Namespace: ""
from server for: "kube-flannel.yml": clusterrolebindings.rbac.authorization.k8s.io "flannel" is forbidden: User "system:node:zzyk8s01" cannot get resource "clusterrolebindings" in API group "rbac.authorization.k8s.io" at the cluster scope
Error from server (Forbidden): error when retrieving current configuration of:
Resource: "/v1, Resource=serviceaccounts", GroupVersionKind: "/v1, Kind=ServiceAccount"
Name: "flannel", Namespace: "kube-system"
from server for: "kube-flannel.yml": serviceaccounts "flannel" is forbidden: User "system:node:zzyk8s01" cannot get resource "serviceaccounts" in API group "" in the namespace "kube-system": can only create tokens for individual service accounts
Error from server (Forbidden): error when retrieving current configuration of:
Resource: "/v1, Resource=configmaps", GroupVersionKind: "/v1, Kind=ConfigMap"
Name: "kube-flannel-cfg", Namespace: "kube-system"
from server for: "kube-flannel.yml": configmaps "kube-flannel-cfg" is forbidden: User "system:node:zzyk8s01" cannot get resource "configmaps" in API group "" in the namespace "kube-system": no relationship found between node 'zzyk8s01' and this object
Error from server (Forbidden): error when retrieving current configuration of:
Resource: "apps/v1, Resource=daemonsets", GroupVersionKind: "apps/v1, Kind=DaemonSet"
Name: "kube-flannel-ds", Namespace: "kube-system"
from server for: "kube-flannel.yml": daemonsets.apps "kube-flannel-ds" is forbidden: User "system:node:zzyk8s01" cannot get resource "daemonsets" in API group "apps" in the namespace "kube-system"
[root@zzyk8s01 scripts]# 

二、解决方法

这可能是由于config没有更新导致的,/root/.kube/config是从/etc/kubernetes/admin.conf复制而来。复制来之后,是需要执行更新kubeconfig命令的。

2.1 更新 kubeconfig 命令:

export KUBECONFIG=/root/.kube/config
chmod g-r /root/.kube/config

2.2 再次执行安装flannel的命令

提示各种OK

[root@zzyk8s01 scripts]# kubectl apply -f kube-flannel.yml            
Warning: policy/v1beta1 PodSecurityPolicy is deprecated in v1.21+, unavailable in v1.25+
podsecuritypolicy.policy/psp.flannel.unprivileged created
clusterrole.rbac.authorization.k8s.io/flannel created
clusterrolebinding.rbac.authorization.k8s.io/flannel created
serviceaccount/flannel created
configmap/kube-flannel-cfg created
daemonset.apps/kube-flannel-ds created

2.3 查看flannel的运行情况

显示各种Running

[root@zzyk8s01 scripts]# kubectl get pods -n kube-system
NAME                               READY   STATUS    RESTARTS   AGE
coredns-78fcd69978-vlzpd           1/1     Running   0          2d16h
coredns-78fcd69978-vmtdm           1/1     Running   0          2d16h
etcd-zzyk8s01                      1/1     Running   1          2d16h
kube-apiserver-zzyk8s01            1/1     Running   1          2d16h
kube-controller-manager-zzyk8s01   1/1     Running   2          2d16h
kube-flannel-ds-fpzm9              1/1     Running   0          36s
kube-flannel-ds-gkgnz              1/1     Running   0          36s
kube-flannel-ds-tmb5s              1/1     Running   0          36s
kube-proxy-2gxv9                   1/1     Running   0          2d16h
kube-proxy-h2zdl                   1/1     Running   0          2d16h
kube-proxy-v6drm                   1/1     Running   1          2d16h
kube-scheduler-zzyk8s01            1/1     Running   2          2d16h

2.4 查看flannel网络情况

如下图,cni0和flannel.1网络都UP状态在这里插入图片描述

三、附上 kube-flannel.yml的文件

---
apiVersion: policy/v1beta1
kind: PodSecurityPolicy
metadata:
  name: psp.flannel.unprivileged
  annotations:
    seccomp.security.alpha.kubernetes.io/allowedProfileNames: docker/default
    seccomp.security.alpha.kubernetes.io/defaultProfileName: docker/default
    apparmor.security.beta.kubernetes.io/allowedProfileNames: runtime/default
    apparmor.security.beta.kubernetes.io/defaultProfileName: runtime/default
spec:
  privileged: false
  volumes:
  - configMap
  - secret
  - emptyDir
  - hostPath
  allowedHostPaths:
  - pathPrefix: "/etc/cni/net.d"
  - pathPrefix: "/etc/kube-flannel"
  - pathPrefix: "/run/flannel"
  readOnlyRootFilesystem: false
  # Users and groups
  runAsUser:
    rule: RunAsAny
  supplementalGroups:
    rule: RunAsAny
  fsGroup:
    rule: RunAsAny
  # Privilege Escalation
  allowPrivilegeEscalation: false
  defaultAllowPrivilegeEscalation: false
  # Capabilities
  allowedCapabilities: ['NET_ADMIN', 'NET_RAW']
  defaultAddCapabilities: []
  requiredDropCapabilities: []
  # Host namespaces
  hostPID: false
  hostIPC: false
  hostNetwork: true
  hostPorts:
  - min: 0
    max: 65535
  # SELinux
  seLinux:
    # SELinux is unused in CaaSP
    rule: 'RunAsAny'
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: flannel
rules:
- apiGroups: ['extensions']
  resources: ['podsecuritypolicies']
  verbs: ['use']
  resourceNames: ['psp.flannel.unprivileged']
- 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
  labels:
    tier: node
    app: flannel
data:
  cni-conf.json: |
    {
      "name": "cbr0",
      "cniVersion": "0.3.1",
      "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
      hostNetwork: true
      priorityClassName: system-node-critical
      tolerations:
      - operator: Exists
        effect: NoSchedule
      serviceAccountName: flannel
      initContainers:
      - name: install-cni
        image: jmgao1983/flannel #quay.io/coreos/flannel:v0.13.1-rc2
        command:
        - cp
        args:
        - -f
        - /etc/kube-flannel/cni-conf.json
        - /etc/cni/net.d/10-flannel.conflist
        volumeMounts:
        - name: cni
          mountPath: /etc/cni/net.d
        - name: flannel-cfg
          mountPath: /etc/kube-flannel/
      containers:
      - name: kube-flannel
        image: jmgao1983/flannel #quay.io/coreos/flannel:v0.13.1-rc2
        command:
        - /opt/bin/flanneld
        args:
        - --ip-masq
        - --kube-subnet-mgr
        resources:
          requests:
            cpu: "100m"
            memory: "50Mi"
          limits:
            cpu: "100m"
            memory: "50Mi"
        securityContext:
          privileged: false
          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: flannel-cfg
          mountPath: /etc/kube-flannel/
      volumes:
      - name: run
        hostPath:
          path: /run/flannel
      - name: cni
        hostPath:
          path: /etc/cni/net.d
      - name: flannel-cfg
        configMap:
          name: kube-flannel-cfg

END

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1130737.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

Vue中使用Web Serial API连接串口,实现通信交互

Vue中使用Web Serial API连接串口,实现通信交互 Web Serial API,web端通过串口与硬件通信; 该API是JS本身 navigator 对象上就独有的,所以与Vue和React框架开发都没有太大的关系, 串口是一个双向通信接口,允许字节发送…

ES6 模块化编程 详解

目录 一、基本介绍 二、基本原理示意图 三、传统CommonJS实现模块化编程 1.介绍 : 2.实例 : 四、ES6新特性实现模块化编程 1.介绍 : 2.实例 : 一、基本介绍 (1) ES6新特性——模块化编程,用于解决传统非模块化开发中出现的"命名冲突", "文件…

LDAP和Kerberos疑难问题诊断方法

不同的工具和方法总能给问题的解决带来希望。本文使用SSSD工具诊断Kerberos和LDAP登录问题诊断。后端(通常也称为数据提供程序)是管理和创建缓存的 SSSD 子进程。此过程与LDAP服务器通信,执行不同的查找查询并将结果存储在缓存中。它还针对 L…

PY32F002A系列单片机:高性价比、低功耗,满足多样化应用需求

PY32F002A系列微控制器是一款高性能、低功耗的MCU,它采用32位ARM Cortex-M0内核,最高工作频率达到24MHz,提供了强大的计算能力。此外,PY32F002A拥有最大20Kbytes的flash存储器和3Kbytes的SRAM,为简单的数据处理提供了充…

一文速通Nginx网关与gateway网关区分

目录 API网关介绍 gateway基本介绍 Nginx基本介绍 Nginx与API gateway网关 API网关介绍 网关的角色是作为一个 API 架构,用来保护、增强和控制对于 API 服务的访问。API 网关是一个处于应用程序或服务(提供 REST API 接口服务)之前的系…

创建 Edge 浏览器扩展教程(上)

创建 Edge 浏览器扩展教程(上) 介绍开始之前后续步骤开始之前1:创建清单 .json 文件2 :添加图标3:打开默认弹出对话框 介绍 在如今日益数字化的时代,浏览器插件在提升用户体验、增加功能以及改善工作流程方…

Spring Authorization Server 1.1 扩展 OAuth2 密码模式与 Spring Cloud Gateway 整合实战

目录 前言无图无真相创建数据库授权服务器maven 依赖application.yml授权服务器配置AuthorizationServierConfigDefaultSecutiryConfig 密码模式扩展PasswordAuthenticationTokenPasswordAuthenticationConverterPasswordAuthenticationProvider JWT 自定义字段自定义认证响应认…

【AI视野·今日Robot 机器人论文速览 第五十八期】Thu, 19 Oct 2023

AI视野今日CS.Robotics 机器人学论文速览 Thu, 19 Oct 2023 Totally 25 papers 👉上期速览✈更多精彩请移步主页 Daily Robotics Papers InViG: Benchmarking Interactive Visual Grounding with 500K Human-Robot Interactions Authors Hanbo Zhang, Jie Xu, Yuch…

『heqingchun-Qt的艺术-优雅界面设计开发』

Qt的艺术-优雅界面设计开发 效果图 一、新建Qt窗口工程 二、准备资源文件 1.图标资源 链接: 图标资源 2.Qss资源 链接: Qss资源 三、设计开发 项目源码链接: CSDN资源

随机生成一个指定边数多边形

随机生成一个指定边数多边形 算法背景:我们想完成一个可以随机生成指定边数多边形的算法。在生成过程中,需要避免随机点连接过程中交叉的问题。 算法步骤   1、为了随机生成一个n边形,我们先随机生成n个点。例如下图,我们随机生…

AI Chatbot 对企业降低人力成本和提高竞争力的作用

随着人工智能技术的发展,越来越多的企业开始尝试将AI ChatBot引入到业务中。AI Chatbot是一种基于人工智能技术的智能对话机器人。它可以模拟人类对话,通过自然语言处理和机器学习算法来理解和回答用户的问题,可以帮助企业降低成本和提高效率…

ExoPlayer架构详解与源码分析(7)——SampleQueue

系列文章目录 ExoPlayer架构详解与源码分析(1)——前言 ExoPlayer架构详解与源码分析(2)——Player ExoPlayer架构详解与源码分析(3)——Timeline ExoPlayer架构详解与源码分析(4)—…

上海亚商投顾:沪指放量反弹 两市超4500股飘红

上海亚商投顾前言:无惧大盘涨跌,解密龙虎榜资金,跟踪一线游资和机构资金动向,识别短期热点和强势个股。 一.市场情绪 三大指数昨日集体反弹,深成指、创业板指盘中涨超1%,黄白二线大幅分化,题材…

视频配音软件有哪些?推荐几款好用的视频配音软件

视频配音软件有哪些?推荐几款好用的视频配音软件 不知道大家有没有这样的体会,我们在观看视频作品的时候,如果没有声音,就会少了很多韵味和可供思索的空间,相反,好的配音可以为作品增色,一句台…

docker 搭建 flink 并上传任务

文章目录 一、docker 搭建 flink1、选择合适的 flink 版本2、重新创建 JobManager、TaskManager 容器并挂载配置文件 二、flink 简单示例1、创建项目架构2、批处理简单示例3、流处理简单示例4、上传 flink 集群①、UI 界面提交任务②、命令提交任务 5、web-ui 提交查看撤销任务…

区块链技术与应用 【全国职业院校技能大赛国赛题目解析】第五套区块链系统部署与运维

第五套区块链系统部署与运维题目 环境 : ubuntu20 fisco : 2.8.0 子任务1-2-1: 登陆Linux服务器,安装并部署下图所示的单机、四机构、三群组、八节点的星形组网拓扑区块链系统,具体工作内容如下 此题在官网有例子如图: 每个机构拥有两个节点,机构A属于中心,属于群组1,…

Linux文件系统 struct dentry 结构体解析

文章目录 前言一、目录项简介二、struct dentry2.1 简介2.2 dentry和inode关联2.3 目录项状态2.4 目录项特点 三、dentry cache3.1 简介3.2 dentry cache 初始化3.3 dentry cache 查看 四、dentry与mount、file的关联五、其他参考资料 前言 这两篇文章介绍了: VFS 之 struct f…

10月26日,起立LG新品首发第五代OLED透明显示屏

“聚力蓝海显示屏,合作共赢”,10月26号14:30分,起立携手LG于德金会展国际酒店,对起立自主研发新品第五代OLED透明显示屏首发,欢迎各大商业人士莅临参与,一起挖掘显示屏在当下内卷泛滥的时代新商机。 一、央…

微信小程序设计之主体文件app-wxss/less

一、新建一个项目 首先,下载微信小程序开发工具,具体下载方式可以参考文章《微信小程序开发者工具下载》。 然后,注册小程序账号,具体注册方法,可以参考文章《微信小程序个人账号申请和配置详细教程》。 在得到了测…

JDK JVM JRE和Java API的关系

Java SE 英文全称是Java Standared Edition,它是Java的标准版。 Java SE由四部分组成:JDK JVM JRE和Java语言。 1.JDK Java Development Kit Java开发工具包。包含了所有编译,运行Java程序所需要的工具,还包含了Java运行环境&a…