Helm:问题对应:k3s下使用helm 3提示Kubernetes cluster unreachable

在k3s 1.0.0版本安装之后使用helm 3时提示Kubernetes cluster unreachable,手动指定KUBECONFIG即可解决此问题。

现象

在使用helm install安装时提示Kubernetes cluster unreachable的错误信息

[root@liumiaocn ~]# helm install excited-squid stable/mysql
Error: Kubernetes cluster unreachable
[root@liumiaocn ~]#

环境准备

  • k3s环境准备
    可参照:https://liumiaocn.blog.csdn.net/article/details/103318341

  • helm 3安装
    可参照:https://liumiaocn.blog.csdn.net/article/details/103360312

[root@liumiaocn ~]# kubectl version
Client Version: version.Info{Major:"1", Minor:"16", GitVersion:"v1.16.3-k3s.2", GitCommit:"e7e6a3c4e9a7d80b87793612730d10a863a25980", GitTreeState:"clean", BuildDate:"2019-11-18T18:31:23Z", GoVersion:"go1.13.4", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"16", GitVersion:"v1.16.3-k3s.2", GitCommit:"e7e6a3c4e9a7d80b87793612730d10a863a25980", GitTreeState:"clean", BuildDate:"2019-11-18T18:31:23Z", GoVersion:"go1.13.4", Compiler:"gc", Platform:"linux/amd64"}
[root@liumiaocn ~]# 
[root@liumiaocn ~]# helm version
version.BuildInfo{Version:"v3.0.0", GitCommit:"e29ce2a54e96cd02ccfce88bee4f58bb6e2a28b6", GitTreeState:"clean", GoVersion:"go1.13.4"}
[root@liumiaocn ~]#

问题再现

[root@liumiaocn ~]# helm list
NAME	NAMESPACE	REVISION	UPDATED	STATUS	CHART	APP VERSION
[root@liumiaocn ~]# 
[root@liumiaocn ~]# helm repo list
Error: no repositories to show
[root@liumiaocn ~]# 
[root@liumiaocn ~]# helm repo add stable https://kubernetes-charts.storage.googleapis.com
"stable" has been added to your repositories
[root@liumiaocn ~]# 
[root@liumiaocn ~]# helm repo list
NAME  	URL                                             
stable	https://kubernetes-charts.storage.googleapis.com
[root@liumiaocn ~]# 
[root@liumiaocn ~]# helm ls
NAME	NAMESPACE	REVISION	UPDATED	STATUS	CHART	APP VERSION
[root@liumiaocn ~]# 
[root@liumiaocn ~]# helm install excited-squid stable/mysql
Error: Kubernetes cluster unreachable
[root@liumiaocn ~]# 

对应方法

因为使用的是k3s的集群,只需执行如下命令手动指定KUBECONFIG的位置即可。

执行命令:export KUBECONFIG=/etc/rancher/k3s/k3s.yaml

结果确认

[root@liumiaocn ~]# export KUBECONFIG=/etc/rancher/k3s/k3s.yaml
[root@liumiaocn ~]# helm install excited-squid stable/mysql
NAME: excited-squid
LAST DEPLOYED: Wed Dec  4 05:29:35 2019
NAMESPACE: default
STATUS: deployed
REVISION: 1
NOTES:
MySQL can be accessed via port 3306 on the following DNS name from within your cluster:
excited-squid-mysql.default.svc.cluster.local

To get your root password run:

    MYSQL_ROOT_PASSWORD=$(kubectl get secret --namespace default excited-squid-mysql -o jsonpath="{.data.mysql-root-password}" | base64 --decode; echo)

To connect to your database:

1. Run an Ubuntu pod that you can use as a client:

    kubectl run -i --tty ubuntu --image=ubuntu:16.04 --restart=Never -- bash -il

2. Install the mysql client:

    $ apt-get update && apt-get install mysql-client -y

3. Connect using the mysql cli, then provide your password:
    $ mysql -h excited-squid-mysql -p

To connect to your database directly from outside the K8s cluster:
    MYSQL_HOST=127.0.0.1
    MYSQL_PORT=3306

    # Execute the following command to route the connection:
    kubectl port-forward svc/excited-squid-mysql 3306

    mysql -h ${MYSQL_HOST} -P${MYSQL_PORT} -u root -p${MYSQL_ROOT_PASSWORD}
[root@liumiaocn ~]#

稍等之后确认结果如下所示

[root@liumiaocn ~]# kubectl get pods
NAME                                   READY   STATUS    RESTARTS   AGE
excited-squid-mysql-649c99cbcf-2n6xs   1/1     Running   0          14m
[root@liumiaocn ~]#

参考内容

https://github.com/rancher/k3s/issues/1126

你可能感兴趣的:(#,K3S,#,Helm)