<p>I want to add admission-controller config and audit policy yaml to the kube api server. I have kept both these files on a folder under /etc/kubernetes/configs and adding it as a volume/volumeMount to the POD.</p>
<p>The pods fails to get the config files from the location despite not getting any errors. What am I doing wrong?</p>
<blockquote>
<p>Error: failed to initialize admission: failed to read plugin config: unable to read admission control configuration from &quot;/etc/kubernetes/configs/admission-controller.yaml&quot; [open /etc/kubernetes/configs/admission-controller.yaml: no such file or directory]</p>
</blockquote>
<p>kube-apiserver.yaml</p>
<pre><code>apiVersion: v1
kind: Pod
metadata:
  annotations:
    kubeadm.kubernetes.io/kube-apiserver.advertise-address.endpoint: 192.168.1.45:6443
  creationTimestamp: null
  labels:
    component: kube-apiserver
    tier: control-plane
  name: kube-apiserver
  namespace: kube-system
spec:
  containers:
  - command:
    - kube-apiserver
    - --service-account-lookup=true
    - --request-timeout=300s
    #- --audit-log-maxsize=100
    #- --audit-log-maxbackup=10
    #- --audit-log-maxage=30
    #- --audit-policy-file=/etc/kubernetes/pki/audit-policy.yaml
    #- --audit-log-path=/var/log/audit/audit.log
    - --profiling=false
    - --admission-control-config-file=/etc/kubernetes/configs/admission-controller.yaml
    - --kubelet-certificate-authority=/etc/kubernetes/pki/ca.crt 
    - --kubelet-https=true
    - --anonymous-auth=false
    - --advertise-address=192.168.1.45
    - --allow-privileged=true
    - --authorization-mode=Node,RBAC
    - --client-ca-file=/etc/kubernetes/pki/ca.crt
    - --enable-admission-plugins=NodeRestriction,EventRateLimit,AlwaysPullImages,PodSecurityPolicy
    - --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-issuer=https://kubernetes.default.svc.cluster.local
    - --service-account-key-file=/etc/kubernetes/pki/sa.pub
    - --service-account-signing-key-file=/etc/kubernetes/pki/sa.key
    - --service-cluster-ip-range=10.96.0.0/12
    - --tls-cert-file=/etc/kubernetes/pki/apiserver.crt
    - --tls-private-key-file=/etc/kubernetes/pki/apiserver.key
    image: k8s.gcr.io/kube-apiserver:v1.21.4
    imagePullPolicy: IfNotPresent
    livenessProbe:
      failureThreshold: 8
      httpGet:
        host: 192.168.1.45
        path: /livez
        port: 6443
        scheme: HTTPS
      initialDelaySeconds: 10
      periodSeconds: 10
      timeoutSeconds: 15
    name: kube-apiserver
    readinessProbe:
      failureThreshold: 3
      httpGet:
        host: 192.168.1.45
        path: /readyz
        port: 6443
        scheme: HTTPS
      periodSeconds: 1
      timeoutSeconds: 15
    resources:
      requests:
        cpu: 250m
    startupProbe:
      failureThreshold: 24
      httpGet:
        host: 192.168.1.45
        path: /livez
        port: 6443
        scheme: HTTPS
      initialDelaySeconds: 10
      periodSeconds: 10
      timeoutSeconds: 15
    volumeMounts:
    - name: configfiles
      mountPath: /etc/kubernetes/configs
      readOnly: false
    - name: auditlog
      mountPath: /var/log/audit
      readOnly: false
    - mountPath: /etc/ssl/certs
      name: ca-certs
      readOnly: true
    - mountPath: /etc/pki
      name: etc-pki
      readOnly: true
    - mountPath: /etc/kubernetes/pki
      name: k8s-certs
      readOnly: true
  hostNetwork: true
  priorityClassName: system-node-critical
  volumes:
  - name: auditlog
    hostpath:
      path: /var/log/kubernetes
      type: DirectoryOrCreate
  - name: configfiles
    hostpath:
      path: /etc/kubernetes/configs
      type: DirectoryOrCreate
  - hostPath:
      path: /etc/ssl/certs
      type: DirectoryOrCreate
    name: ca-certs
  - hostPath:
      path: /etc/pki
      type: DirectoryOrCreate
    name: etc-pki
  - hostPath:
      path: /etc/kubernetes/pki
      type: DirectoryOrCreate
    name: k8s-certs
status: {}
</code></pre>
<pre><code>[root@controlplane ~]# ls -lrt /etc/kubernetes/configs
total 16
-rw------- 1 root root  175 Aug 21 09:36 eventconfig.yaml
-rw------- 1 root root  125 Aug 21 09:36 admission-controller.yaml
-rw------- 1 root root 2219 Aug 21 16:15 audit-policy.yaml_back
-rw------- 1 root root 2219 Aug 21 16:39 audit-policy.yaml
[root@controlplane ~]#
</code></pre>

pocman
<p>The mistake was due to the hostPath not being in camel case, changed it to resolve the issue.</p>
<pre><code>  - name: auditlog
    hostPath:
      path: /var/log/kubernetes
      type: DirectoryOrCreate
  - name: configfiles
    hostPath:
      path: /etc/kubernetes/configs
      type: DirectoryOrCreate
</code></pre>
