k8s特权容器配置

  • 确认kube-api是否开启了privileged参数
  • [root@node1 ~]# ps -ef | grep privileged
    root 5041 5016 3 Feb17 ? 00:36:37 kube-apiserver --advertise-address=172.30.201.221 --allow-privileged=true --authorization-mode=Node,RBAC --client-ca-file=/etc/kubernetes/pki/ca.crt --enable-admission-plugins=NodeRestriction --enable-bootstrap-token-auth=true --etcd-cafile=/etc/kubernetes/pki/etcd/ca.crt --etcd-certfile=/etc/kubernetes/pki/apiserver-etcd-client.crt --etcd-keyfile=/etc/kubernetes/pki/apiserver-etcd-client.key --etcd-servers=https://127.0.0.1:2379 --insecure-port=0 --kubelet-client-certificate=/etc/kubernetes/pki/apiserver-kubelet-client.crt --kubelet-client-key=/etc/kubernetes/pki/apiserver-kubelet-client.key --kubelet-preferred-address-types=InternalIP,ExternalIP,Hostname --proxy-client-cert-file=/etc/kubernetes/pki/front-proxy-client.crt --proxy-client-key-file=/etc/kubernetes/pki/front-proxy-client.key --requestheader-allowed-names=front-proxy-client --requestheader-client-ca-file=/etc/kubernetes/pki/front-proxy-ca.crt --requestheader-extra-headers-prefix=X-Remote-Extra- --requestheader-group-headers=X-Remote-Group --requestheader-username-headers=X-Remote-User --secure-port=6443 --service-account-key-file=/etc/kubernetes/pki/sa.pub --service-cluster-ip-range=10.96.0.0/16 --tls-cert-file=/etc/kubernetes/pki/apiserver.crt --tls-private-key-file=/etc/kubernetes/pki/apiserver.key --feature-gates=RemoveSelfLink=false

    可以看到 --allow-privileged=true已经开启root权限。

  • 编辑pod.yaml文件:
  • apiVersion: v1
    kind: Pod
    metadata:
    name: test-pod
    spec:
    containers:
    - name: hello-world-container
    image: nginx:latest
    securityContext: ###添加参数启用容器root权限
    privileged: true
    capabilities:
    add: ["SYS_ADMIN"]
    runAsUser: 0

    之后可以进入容器使用root权限

posted @ 2022-08-11 10:40  追梦boyaaa  阅读(1901)  评论(0编辑  收藏  举报