First of all check if your cluster is up and running:
$ ps aux | grep apiserver
$ ps aux | grep etcd
$ docker ps
You should see all necessary kubernetes processes running like
If cluster is ready, you can try to access
By default, kubectl takes its configuration from file
Default behavior can be changed by setting environment variable
kubectl read all configuration files listed in this variable and merge their configuration settings.
This way you can have the configuration for several clusters in separate files for easy maintenance.
In this case you should set
KUBECONFIG variable in user profile, to be sure it has correct value after next login.
The other way to use specific config file is to set
--kubeconfig argument in the command line
$ kubectl --kubeconfig config_file_path <other_command_line_arguments>
You can check available configuration (sensitive information will be suppressed) by running following command:
# kubectl config view
There is a possibility to configure multiple context in one config file and to switch the context by specifying its name in command line. It is useful if you are managing several clusters (or different service accounts for the same cluster) using the same user account.
$ kubectl config --kubeconfig=config-demo use-context exp-scratch <other_command_line_arguments>
Check out the documentation for details.
When you create a cluster with the command
kubeadm init , it adds the connection configuration for the
kubectl to the file
-rw------- 1 root root 5446 May 1 11:11 admin.conf
You can specify it as
kubectl config file directly if you are using root account.
To use it with different user account, you need to copy it to user's
$HOME/.kube/config file and make it accessible by user.
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
It's enough to do it only once for each user's account which you plan to use for cluster management.
This is a regular file and it doesn't disappear after reboot, so you should still be able to access Kubernetes cluster running
If you reset the cluster with
kubeadm reset and create it again, you need to update your
kubectl connection configuration in the user profile, because previous cluster credentials will not work with new cluster.