Tuesday, July 9, 2019

UBUNTU18+KVM+VAGRANT+KUBERNETES 12)control cluster from (kubectl command) local host.

 UBUNTU18+KVM+VAGRANT+KUBERNETES 12)control cluster from (kubectl command) local host.


HI.!
This very short article shows how to control your cluster from local host.
Prereq)
Linux command basic, kubernetes kubeadm cluster...that you can find from googling or my blog!

https://wnapdlf.blogspot.com/

UBUNTU18+KVM+VAGRANT+K8S 1)INSTALL KVM
UBUNTU18+KVM+VAGRANT+K8S 2)INSTALL VAGRANT
UBUNTU18+KVM+VAGRANT+K8S 3)INSTALL K8S


oyj@Workstation-oyj-X555QG ~/u18kvk8s/k8s$kubectl

Command 'kubectl' not found, but can be installed with:

sudo snap install kubectl

oyj@Workstation-oyj-X555QG ~/u18kvk8s/k8s$


#Well I am going to use shell script this time

oyj@Workstation-oyj-X555QG ~/u18kvk8s/k8s$cat conTfromLoal.sh
#!/usr/bin/env bash
#This simple script is for downloading kubectl binary and then configure to control kubernetes cluster from local pc,not k8s master node(laptop and etc)

if [[ ! -e $HOME/bin ]]
then
   mkdir $HOME/bin
else
   echo "$HOME/bin/ exists"
fi

KUB=$(which kubectl)
if [[ -z $KUB ]]
then
 echo -e "\e[35m Downloading kubectl from official..site \e[0m"
 curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
 mv kubectl $HOME/bin
 chmod 700 $HOME/bin/kubectl
else
 echo "kubectl already exists"
fi

if [[ ! -e $HOME/.kube ]]
then
   mkdir $HOME/.kube
else
   echo "kube directory already exists"
fi

echo "Direct into ~/.kube/config2"
#10.1.0.2 is master k8s nodes
ssh -i id_rsa vagrant@10.1.0.2 'sudo cat /etc/kubernetes/admin.conf' > ~/.kube/config2

echo "export KUBECONFIG=$HOME/.kube/config2" >> $HOME/.bashrc
$HOME/bin/kubectl get nodes

echo -e "\e[35m You do not need to login master k8s node every time! Congratula..! \e[0m"
exec bash
oyj@Workstation-oyj-X555QG ~/u18kvk8s/k8s$bash conTfromLoal.sh
/home/oyj/bin/ exists
 Downloading kubectl from official..site
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 40.9M  100 40.9M    0     0  9872k      0  0:00:04  0:00:04 --:--:-- 9872k
kube directory already exists
Direct into ~/.kube/config2
NAME          STATUS     ROLES    AGE     VERSION
kubemaster    Ready      master   2d21h   v1.15.0
kubeworker1   Ready      <none>   2d21h   v1.15.0
kubeworker2   Ready      <none>   2d21h   v1.15.0
kubeworker3  Ready   <none>   2d21h   v1.15.0
 You do not need to login master k8s node every time! Congratula..!
oyj@Workstation-oyj-X555QG ~/u18kvk8s/k8s$kubectl get po
No resources found.
oyj@Workstation-oyj-X555QG ~/u18kvk8s/k8s$kubectl get po -n kube-system
NAME                                 READY   STATUS    RESTARTS   AGE
coredns-5c98db65d4-2k8ds             1/1     Running   1          2d21h
coredns-5c98db65d4-cw62m             1/1     Running   1          2d21h
etcd-kubemaster                      1/1     Running   1          2d21h
kube-apiserver-kubemaster            1/1     Running   1          2d21h
kube-controller-manager-kubemaster   1/1     Running   1          2d21h
kube-flannel-ds-amd64-4gxd4          1/1     Running   1          2d21h
kube-flannel-ds-amd64-h7p2t          1/1     Running   1          2d21h
kube-flannel-ds-amd64-rll7d          1/1     Running   3          2d21h
kube-flannel-ds-amd64-z6mj9          1/1     Running   1          2d21h
kube-proxy-489rf                     1/1     Running   1          2d21h
kube-proxy-4cgcn                     1/1     Running   1          2d21h
kube-proxy-bxpgm                     1/1     Running   1          2d21h
kube-proxy-wgq4c                     1/1     Running   1          2d21h
kube-scheduler-kubemaster            1/1     Running   1          2d21h


Thanks for reading.

No comments:

Post a Comment