-
Notifications
You must be signed in to change notification settings - Fork 29
Kubernetes with Kubespray
- Prerequisite
- Install and configure Kubespray
- Setting up Helm
- SSH Config
- Using SSHFS to Mount Vagrant on Mac
- Remote Kubernetes Cluster
- K8s Dashboard
- macOS: 10.14 (Mojave)
- Vagrant: 2.2.4
- Ansible: 2.7.9
- Kubespray
git clone [email protected]:kubernetes-sigs/kubespray.git
cd kubespray
mv inventory/sample/{hosts.ini,hosts.ini.bak}
sed -i -e 's/"download_run_once": "True",/"download_run_once": "False",/' Vagrantfile
vagrant up
This will spin up 3 VMs and install kubernetes on them. Once they are completed you can connect to any of them by running
$ vagrant ssh k8s-1
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
vagrant@k8s-1:~$ kubectl get nodes -o=wide
NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME
k8s-1 Ready master,node 20h v1.13.5 172.17.8.101 <none> Ubuntu 18.04.2 LTS 4.15.0-46-generic docker://18.6.2
k8s-2 Ready master,node 20h v1.13.5 172.17.8.102 <none> Ubuntu 18.04.2 LTS 4.15.0-46-generic docker://18.6.2
k8s-3 Ready node 20h v1.13.5 172.17.8.103 <none> Ubuntu 18.04.2 LTS 4.15.0-46-generic docker://18.6.2
Run the following command and then close the current terminal session by running exit
command
vagrant@k8s-1:~$ sudo usermod -a -G docker $USER
Now close the current terminal session
vagrant@k8s-1:~$ exit
If you get an error like the one below,
The connection to the server localhost:8080 was refused - did you specify the right host or port?
Run the following command to solved this issue:
sudo cp /etc/kubernetes/admin.conf $HOME/ && sudo chown $(id -u):$(id -g) $HOME/admin.conf && export KUBECONFIG=$HOME/admin.conf
Now run the command again:
vagrant@k8s-1:~$ kubectl get nodes
If you want to ssh
into your vagrant box without switching into the project directory and typing vagrant ssh k8s-1
. Simply copy vagrant ssh-config
to your ~/.ssh/config
$ cd ~/Vagrant
$ vagrant ssh-config >> ~/.ssh/config
This will allow you to use ssh k8s-1
from anywhere.
Copy your public key to your Vagrant box
$ ssh-copy-id vagrant@k8s-1
Create a local directory
$ mkdir ~/Desktop/k8s
Mounting your remote directory
$ sshfs vagrant@k8s-1:/home/vagrant ~/Desktop/k8s
To connect to a remote Kubernetes cluster from you Mac, you'll need copy the Kubernetes credentials to your home directory as shown below.
scp -r vagrant@k8s-1:/home/vagrant/.kube ~/.kube/
That’s all you have to do. Your local Kubectl should be able to connect with the remote Kubernetes cluster now.