Error in setting user credentials in kubectl configurations

12/24/2020

I am working on a Minikube cluster in Windows environment for learning purposes. I am trying out some authentication and authorization methods. Following are the steps involved.

  • Created a private key using openssl
  • Created a certificate signing request using openssl
  • Created a YAML manifest for a certificate signing request object
apiVersion: certificates.k8s.io/v1
kind: CertificateSigningRequest
metadata:
  name: student-csr
spec:
  groups:
 - system:authenticated
  request: <encoded value>
  signerName: kubernetes.io/kube-apiserver-client
  usages:
 - digital signature
 - key encipherment
 - client auth

I have provided base64 encoded value of certificate content as the value for request field.

  • Created certificate signing request object
kubectl create -f signing-request.yaml
  • Approved certificate signing request
kubectl certificate approve student-csr
  • Extracted the approved certificate from the certificate signing request, decoded it with base64 and saved it as a certificate file
kubectl get csr student-csr -o jsonpath='{.status.certificate}' | base64 --decode > student.crt

Now, when I try to configure kubectl client configuration with student user's credentials by providing key and certificate,

kubectl config set-credentials student --client-certificate=student.crt --client-key=student.key

it throws the following error.

error: Rel: can't make F:\CKAD\BasicLF\rbac\student.crt relative to C:\Users\Nilucshan\.kube

I am executing my kubectl command from my working directory (F:\CKAD\BasicLF\rbac). kubectl.exe is placed in C drive.

But it works successfully if I place my key and certificate files inside C:\Users\Nilucshan\.kube directory.

What is the problem here? Why isn't it working when my key and certificate files are placed in my working directory?

-- Nilucshan Siva
kubectl
kubernetes
minikube

1 Answer

5/3/2021

I had the same problem doing it from another partition. You can create the directory inside your user folder C:\Users\Nilucshan instead of .kube

-- Santiago
Source: StackOverflow