LoginSignup
1
0

More than 3 years have passed since last update.

kubectlでunable to read client-certのエラーが出たときの対処法

Last updated at Posted at 2020-12-19

minikubeでkubectlを実行した際に、unable to read client-cert のエラーが出たので、その解決方法の備忘録です。
root以外のユーザーで作業していました。

環境

  • CentOS7.9
  • minikube 1.16.0
  • kubectl 1.20.1

エラーの内容

kubectlをインストール後、バージョンを確認しようとしたところ、以下のエラーが出ました。

$ kubectl version
Error in configuration:
* unable to read client-cert /root/.minikube/profiles/minikube/client.crt for minikube due to open /root/.minikube/profiles/minikube/client.crt: permission denied
* unable to read client-key /root/.minikube/profiles/minikube/client.key for minikube due to open /root/.minikube/profiles/minikube/client.key: permission denied
* unable to read certificate-authority /root/.minikube/ca.crt for minikube due to open /root/.minikube/ca.crt: permission denied

原因

原因は minikube start をしたときに以下のメッセージが出るのですが、コマンドを実行しただけで、以下記載の 独自の設定の上書き をしていなかったためです。

❗  kubectl と minikube の構成は /root に保存されます
❗  kubectl か minikube コマンドを独自のユーザーとして使用するには、そのコマンドの再配置が必要な場合があります。たとえば、独自の設定を上書きするには、以下を実行します


    ▪ sudo mv /root/.kube /root/.minikube $HOME
    ▪ sudo chown -R $USER $HOME/.kube $HOME/.minikube

kubectlの設定情報は以下コマンドで確認が出来ます。確かに/rootを見るようになっています。

$ kubectl config view
apiVersion: v1
clusters:
- cluster:
    certificate-authority: /root/.minikube/ca.crt
    server: https://10.0.2.15:8443
  name: minikube
contexts:
- context:
    cluster: minikube
    namespace: default
    user: minikube
  name: minikube
current-context: minikube
kind: Config
preferences: {}
users:
- name: minikube
  user:
    client-certificate: /root/.minikube/profiles/minikube/client.crt
    client-key: /root/.minikube/profiles/minikube/client.key

対応方法

~/.kube/config を開き、/root/ と書かれている部分を自身のホームディレクトリに変更します。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0