Deploying Cloud Foundry on a local Kubernetes

João M Pinto
5 min readFeb 19, 2020

--

I have met a lot of people which uses Docker/Kubernetes but which never used Cloud Foundry so I will start with a short overview.

Overview

Cloud Foundry is an opensource project established in 2011, it is a Platform-As-A-Service framework which provides developers the ability to deploys their applications from a set of supported languages and it provides services that can be made available to those applications (e.g. database service). The applications are provided in the specific language native format, extend with metadata for setting up CF run time specific parameters like resource limits.

Kubernetes is an opensource project established in 2014, it is a container orchestration platform which provides developers the ability to deploy their applications and services from any Docker based image. The applications and services are provided in the format of images and Kubernetes artifacts.

Synergies

As Docker and Kubernetes popularity exploded there was some friction resulting in some “Kubernetes vs Cloud Foundry” debates. I believe that many times this was mostly due to the lack of awareness on the big difference on the governance model, maturity level, life cycle and overall scope of both projects.

Today the synergies between both technologies are much more relevant than their differences in scope, listing some key synergy points:

  • Garden-runc, using Docker’s container runtime (runC) as the default backend
  • Eirini, a pluggable container orchestration for Cloud Foundry with a Kubernetes backend
  • KubeCF, a Kubernetes Deployment (using helm) for CF

Summary

If you are a big fan of Kubernetes you know have yet another good reason to use them, deploying Cloud Foundry :)

Hand’s On

This instructions were created for a Linux systems, might work on other platforms with some adjustments. For the local Kubernetes engine I have selected kind . CF is a large/complex software ecosystem, a system with at least 16GB of RAM and 120GB of free disk space is required.

I must installed the following tools:

  • cf-cli (used version 6.49.0)
  • Docker (used version 19.03.5-ce)
  • Kubectl (used version 1.17.2)
  • Kind (used version 0.7.0)
  • Helm (used version 3.1.0)

Start by creating the kind cluster that will use only for the kubecf demo:

# Create a kind cluster name "kubecf"
kind create cluster --name kubecf
# Setup our kubectl config to use our cluster
kind get kubeconfig --name kubecf > .kubeconfig
KUBECOCONFIG=.kubeconfig

Identify the latest KubeCF release from browsing https://github.com/SUSE/kubecf/releases .

KUBECF_RELEASE=0.2.0

KubeCF depends on cf-operator, a Kubernetes operator that will watch the ‘kubecf’ namespace for *.quarks.cloudfoundry.org objects. When those objects are found, the operator will create the Kubernetes standard objects required to meet the object definitions.

Identify the cf-operator version required by the current kubecf release by looking into it’s build properties in the git repository .

CFOPERATOR_VERSION=v2.0.0-0.g0142d1e9

Create the cf-operaor namespace manually:

kubectl create namespace cf-operator

Deploy the cf-operator help chart setting the namespace that should be watched, the cf-operator will create this namespace.

helm install cf-operator \
--namespace cf-operator \
--set "global.operator.watchNamespace=kubecf" \
https://s3.amazonaws.com/cf-operators/helm-charts/cf-operator-${CFOPERATOR_VERSION}.tgz

You will need to wait several seconds until the two operator pods become ready:

watch 'kubectl -n cf-operator get pods'

Create a sample configuration file for KubeCF:

node_ip=$(kubectl get node kubecf-control-plane \
--output jsonpath='{ .status.addresses[?(@.type == "InternalIP")].address }')
cat << _EOF_ > values.yaml
system_domain: ${node_ip}.nip.io
services:
router:
externalIPs:
- ${node_ip}
kube:
service_cluster_ip_range: 0.0.0.0/0
pod_cluster_ip_range: 0.0.0.0/0
_EOF_

NOTE: By setting the services.router.externalIPs you will be able to connect direcly from your system to the CF Router pod running in Kind.

Deploy kubecf using helm:

helm install kubecf \
--namespace kubecf \
--values values.yaml \
https://github.com/SUSE/kubecf/releases/download/v${KUBECF_RELEASE}/kubecf-${KUBECF_RELEASE}.tgz

The deployment took me around 30mins, the duration will be highly dependent on your internet connection. Please be aware that it is expected to see “No resources found” for a few minutes, and later a single pod ig-kubecf* will be kept in the “init” phase for a very long time, this pod will download cloud foundry images and store them on the local node for the final deployment.

You may watch the deployment status using:

watch 'kubectl -n kubecf get pods'

Once the deployment is complete you will get 19 pods running :

Once all the full CF instance components are running, you can test it using the CF CLI. “cf api” will point the CF client to api.172.17.0.2.nip.io (this will resolve to the kind node ip from which the cf router pod is exposed). Since we are using the wild card based service nip.io, we will be able to use all the services available from the router based on their hostnames, without any explicit DNS configuration.

The test:

cf api --skip-ssl-validation api.172.17.0.2.nip.io

Result:

We fetch the random generated credentials for the default admin user:

admin_pass=$(kubectl get secret \
--namespace kubecf kubecf.var-cf-admin-password \
-o jsonpath='{.data.password}' \
| base64 --decode)

We authenticate using those credentials:

cf auth admin "${admin_pass}"

From this point on it’s typical Cloud Foundry usage, let’s create a demo organization, a space and a development user:

cf create-org medium.com
cf create-space demo -o medium.com
cf create-user developer password
cf set-space-role developer medium.com demo SpaceDeveloper

Switch to the developer user

cf login -u developer -p password

Now let’s deploy a sample python application:

git clone https://github.com/joaompinto/cf-hello-python-flask.git
cd cf-hello-python-flask
cf push

The application should start:

You will be able to browse/curl the app using the route URL test-python-flask-thankful-randomstuff.172.17.0.2.nip.io .

If you want to test with a larger web app and get a nice web console for CF, you can deploy Stratos, an Open Source Web-based UI (Console) for managing Cloud Foundry.

You will get something like this:

P.S: Yes, after being built it can be deployed to your local CF using “cf push” using the admin user .

This demo was only possible by getting help from the people from #kubecf at https://slack.cloudfoundry.org/ . You probably also noted that SUSE deserves a lot of credit fort his work :)

If you are looking into deploying Cloud Foundry into GKE I recommend the following blog post , reading it actually motivated me for setting up this demo, if it runs on Google’s Cloud it must also run on my laptop.

--

--