diff --git a/README.md b/README.md index 0abff07..cd8e95b 100644 --- a/README.md +++ b/README.md @@ -1,23 +1,20 @@ # Kubernetes cluster A vagrant script for setting up a Kubernetes cluster with a load-balancer and dynamic provisioner using Kubeadm -## Pre-requisites +### Pre-requisites * **[Vagrant 2.1.4+](https://www.vagrantup.com)** * **[Virtualbox 5.2.18+](https://www.virtualbox.org)** -## How to Run +### Start the Base Cluster -Execute the following vagrant command to start a new Kubernetes cluster, this will start one master and three nodes: +Run the following command using CMD/Powershell in the dir where your [Vagrantfile](https://github.com/jprdonnelly/kubernetes-cluster/blob/master/Vagrantfile "Vagrantfile") lives. ``` vagrant up ``` - -You can also start invidual machines by vagrant up k8s-head, vagrant up k8s-node-1 and vagrant up k8s-node-2 - -If more than three nodes are required, you can edit the servers array in the Vagrantfile - +* *When this command finishes you will have (4) running VMs joined together as a K8s cluster.* +* If more than three nodes are required, you can edit the servers array in the Vagrantfile ``` servers = [ { @@ -31,10 +28,66 @@ servers = [ } ] ``` +* As you can see above, you can also configure a static IP address, memory and CPU in the servers array. -As you can see above, you can also configure IP address, memory and CPU in the servers array. +### Check Cluster Health and Update Admin Service Account +``` +PS C:\users\djx\Documents\GitHub\kubernetes-cluster> vagrant ssh k8s-head +Welcome to Ubuntu 18.04.1 LTS (GNU/Linux 4.15.0-38-generic x86_64) + + + +vagrant@k8s-head:~$ kubectl cluster-info +Kubernetes master is running at https://192.168.205.10:6443 +KubeDNS is running at https://192.168.205.10:6443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy + +To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'. + +vagrant@k8s-head:~$ kubectl get nodes +NAME STATUS ROLES AGE VERSION +k8s-head Ready master 14m v1.12.2 +k8s-node-1 Ready 10m v1.12.2 +k8s-node-2 Ready 5m v1.12.2 +k8s-node-3 Ready 34s v1.12.2 + +vagrant@k8s-head:~$ kubectl create clusterrolebinding default-admin --clusterrole cluster-admin --serviceaccount=default:default +clusterrolebinding.rbac.authorization.k8s.io/default-admin created +``` +### Install MetalLB Load Balancer +You can also use the included YAML files to pull and deploy [MetalLB](https://metallb.universe.tf "MetalLB"), a load balancer that will distribute IPs in a given range. This has a lot more functionality than we are using, and you can see the other examples at the [project page](https://metallb.universe.tf). -## Clean-up +### Install NFS Provisioner +``` +vagrant@k8s-head:~$ kubectl label nodes k8s-node-1 role=nfs +node/k8s-node-1 labeled + +vagrant@k8s-head:~$ kubectl apply -f https://raw.githubusercontent.com/jprdonnelly/kubernetes-cluster/master/nfs-provisioner/nfs-deployment.yaml +service/nfs-provisioner created +deployment.apps/nfs-provisioner created + +vagrant@k8s-head:~$ kubectl apply -f https://raw.githubusercontent.com/jprdonnelly/kubernetes-cluster/master/nfs-provisioner/nfs-class.yaml +storageclass.storage.k8s.io/nfs-dynamic created +vagrant@k8s-head:~$ kubectl get svc +NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE +kubernetes ClusterIP 10.96.0.1 443/TCP 18m +nfs-provisioner ClusterIP 10.109.234.184 2049/TCP,20048/TCP,111/TCP,111/UDP 11s + +vagrant@k8s-head:~$ kubectl patch storageclass nfs-dynamic -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"true"}}}' +storageclass.storage.k8s.io/nfs-dynamic patched + +vagrant@k8s-head:~$ kubectl apply -f https://raw.githubusercontent.com/jprdonnelly/kubernetes-cluster/master/qsefe/nfs-vol-pvc.yaml +persistentvolumeclaim/qsefe-vol created + +vagrant@k8s-head:~$ kubectl get pvc +NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE +qsefe-vol Bound pvc-60cd4de4-e372-11e8-84e2-02c44c503abe 5Gi RWX nfs-dynamic 38s + +vagrant@k8s-head:~$ kubectl get pv +NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE +pvc-60cd4de4-e372-11e8-84e2-02c44c503abe 5Gi RWX Delete Bound default/qsefe-vol nfs-dynamic +``` + +### Clean-up Execute the following command to remove the virtual machines created for the Kubernetes cluster. ``` @@ -43,6 +96,6 @@ vagrant destroy -f You can destroy individual machines by vagrant destroy k8s-node-1 -f -## Licensing +##### Licensing [Apache License, Version 2.0](http://opensource.org/licenses/Apache-2.0).