SAK kubectl - Evanto/qna GitHub Wiki
Text
Configure kubectl to manage your Kubernetes cluster
Manage your deployed Kubernetes cluster with kubectl CLI. Make sure that the kubectl version is within one minor version of your cluster's API server:
kubectl version --short
Kubectl uses a file named config
to access Kubernetes clusters. Once you deployed a cluster with Terraform, the config
file is automatically generated for the cluster in your project directory (swiss-army-kube/example
). By default, kubectl checks $HOME/.kube
for the config
file, so move it there.
Alternatively, use an environment variable:
export KUBECONFIG=.config:$HOME/.kube/config
To view your current cluster configuration:
kubectl config view
Check that the deployment succeeded by listing currently deployed pods:
kubectl get pods
Each of your clusters must have a config file.
These files are referred to as kubeconfig files no matter how they are named and store information about your cluster.
Alternatively, if you work with multiple clusters,
Alternatively, you can run:
export KUBECONFIG=$KUBECONFIG:$HOME/.kube/config
or
export KUBECONFIG=./swiss-army-kube/example/config.conf
To view configuration information merged from all the files that are now listed in your KUBECONFIG environment variable, in the example
directory run:
kubectl config view
For more information, check Configure Access to Multiple Clusters
Configure kubectl to use your cluster. In order to start interacting with your Kubernetes cluster, configure kubectl.
To view information about each of the nodes that are in your cluster:
kubectl get nodes
When you use KUBECONFIG environment variable you can only point it to one kubeconfig file and not to a series of kubeconfig files. You need to merge all the individual kubeconfig files into one kubeconfig file and store it as $HOME/.kube/config and then select a cluster using context flag of kubectl.
Kubernetes access multiple cluster with KUBECONFIG variable on Windows
Comments
В квикстарте не хватает инфы, как подключить kubectl - как вообще начать работать с кубером. То есть мы все задеплоили, у нас успешно отработал терраформ - что дальше? Мы его (kubectl) ставим на этапе пререков, разворачиваем кластер терраформом, и у нас в папке example появляется конфигурационный файл (мы к нему конфигурим путь в example.tfvars):
# The kubernetes config file path
config_path = "kubeconfig_swiss-army"
Kubernetes config file appears. We should either:
- copy it to home directory
$HOME/.kube/config
- import it with kubectl add cluster command
Далее есть 2 способа - либо мы этот конфигурационный файл копируем в хоум директорию в скрытую папку .kube:
$HOME/.kube
и получаем $HOME/.kube/config
, либо импортируем его с помощью команд kubectl add cluster - посмотреть в оф. доке кубера параметры импорта нового конфигурационного файла.
Links
Configure Access to Multiple Clusters
How to configure kubectl with cluster information from a .conf file?