12. Kubernetes Setup

This section describes how to set up Kubernetes.

12.1 Kubernetes CLI Installation

First, you need to install the kubectl command-line interface (CLI).

12.1.1 Script Installation

You can use the tools/k8s-helper.sh script to install kubectl. To do so, run the following script:

$ ./tools/minikube-helper download-kubectl

Then the kubectl gets downloaded.

12.1.2 Manual Installation

You can perform a manual installation for either OSX or Linux.

Example for OSX

The following listing shows how to manually install on OSX:

$ curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/darwin/amd64/kubectl
$ chmod +x ./kubectl
$ sudo mv ./kubectl /usr/local/bin/kubectl
----

Example for Linux

The following listing shows how to manually install on Linux:

$ curl -LO 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
$ sudo mv ./kubectl /usr/local/bin/kubectl

See this page for more information.

12.2 Kubernetes Cluster Setup

We need a cluster of Kubernetes. The best choice is Minikube.

[Tip]Tip

You can skip this step if you have a Kubernetes cluster installed and do not want to use Minikube. In that case, the only thing you have to do is to set up spaces.

[Warning]Warning

Servers often run run out of resources at the stage step. If that happens, clear some apps from PCF Dev and continue.

12.2.1 Script Installation

You can use the tools/k8s-helper.sh script to install Minikube. To do so, run the following script:

$ ./tools/minikube-helper download-minikube

Then the Minikube cluster gets downloaded.

12.2.2 Manual Installation

You can perform a manual installation for either OSX or Linux.

Example for OSX

The following listing shows how to manually install on OSX:

$ curl -Lo minikube https://storage.googleapis.com/minikube/releases/v0.20.0/minikube-darwin-amd64 && chmod +x minikube && sudo mv minikube /usr/local/bin/

Feel free to skip running sudo mv minikube /usr/local/bin if you want to add minikube to your path manually.

12.2.3 Example for Linux

The following listing shows how to manually install on Linux:

$ curl -Lo minikube https://storage.googleapis.com/minikube/releases/v0.20.0/minikube-linux-amd64 && chmod +x minikube && sudo mv minikube /usr/local/bin/

You can skip running sudo mv minikube /usr/local/bin if you want to add minikube to your path manually. See this page for more information on the installation.

12.3 Run Minikube

To start Kubernetes on your local box, run minikube start.

To add the dashboard, run minikube dashboard.

12.4 Certificates and Workers

12.4.1 Minikube Certificates and Workers

By default, if you install Minikube, all the certificates get installed in your ~/.minikube folder. Your kubectl configuration under ~/.kube/config also gets updated to use Minikube.

12.4.2 Manual Certificates and Workers Setup

[Note]Note

If you want to run the default demo setup, you can skip this section.

To target a given Kubernetes instance, you need to pass around Certificate Authority key and also user keys.

You can read more about the instructions on how to generate those keys here. Generally speaking, if you have a Kubernetes installation (such as minikube), this step has already been done for you. Now you can reuse those keys on the workers.

The following inormation has been extracted from the Kubernetes official documentation.

Configure kubectl to connect to the target cluster using the following commands, replacing the following values:

  • Replace ${MASTER_HOST} with the master node address or name used in previous steps.
  • Replace ${CA_CERT} with the absolute path to the ca.pem created in previous steps.
  • Replace ${ADMIN_KEY} with the absolute path to the admin-key.pem created in previous steps.
  • Replace ${ADMIN_CERT} with the absolute path to the admin.pem created in previous steps.

The following commands show how to perform these steps:

$ kubectl config set-cluster default-cluster --server=https://${MASTER_HOST} --certificate-authority=${CA_CERT}
$ kubectl config set-credentials default-admin --certificate-authority=${CA_CERT} --client-key=${ADMIN_KEY} --client-certificate=${ADMIN_CERT}
$ kubectl config set-context default-system --cluster=default-cluster --user=default-admin
$ kubectl config use-context default-system

12.5 Generate Minikube Namespaces

With the Minikube cluster running, we need to generate namespaces. To do so, run the ./tools/k8s-helper.sh setup-namespaces.