Problem scenario
You want to create a kubeconfig file automatically. But you do not know how. What should you do?
Prerequisites
If kubelet, kubeadm and kubectl are installed, skip the prerequisites to go to step #1 in the procedures. Otherwise, run these commands:
cd /tmp
curl -Lo kubectl https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl && chmod +x kubectl
curl -Lo kubeadm https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubeadm && chmod +x kubeadm
curl -Lo kubelet https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubelet && chmod +x kubelet
sudo mv /tmp/kube* /usr/bin
If you are running CentOS/RHEL/Fedora, run this command: sudo yum -y install socat ebltables
Procedures
Run this command: sudo kubeadm init
The above command will create this file; it can be a template for a kubeconfig file: /etc/kubernetes/admin.conf
If you want to create one manually, you may want to see this posting.