Limited Time Offer!

For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly.
Master DevOps, SRE, DevSecOps Skills!

Enroll Now

Getting Started with Cloud Foundry for Kubernetes using cf-for-k8s in Linux(Ubuntu)

Step 1- Install the cf CLI Using a Package Manager


# Add the Cloud Foundry Foundation public key and package repository to your system by running:
$ wget -q -O - https://packages.cloudfoundry.org/debian/cli.cloudfoundry.org.key | sudo apt-key add -
$ echo "deb https://packages.cloudfoundry.org/debian stable main" | sudo tee /etc/apt/sources.list.d/cloudfoundry-cli.list

# Update your local package index by running:
sudo apt-get update

# To install cf CLI v7, run:
sudo apt-get install cf7-cli

$ cf version
$ cf --help

Step 2- You will need kubectl to interact with your cluster kubectl install instructions


# Download the latest release with the command:
$ curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"

# Install kubectl
$ sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl

$ kubectl
kubectl version --client

Step 3 – KinD (Kubernetes in Docker) to instantiate your local cluster


$ curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.11.1/kind-linux-amd64
$ chmod +x ./kind
$ mv ./kind /usr/local/bin/kind
$ kind version
$ kind

Step 4 – Install Bosh CLI

Bosh CLI the ./hack/generate-values.sh script will use the Bosh CLI to generate certificates, keys, and passwords in the file ./cf-install-values.yml


$ wget https://github.com/cloudfoundry/bosh-cli/releases/download/v6.4.4/bosh-cli-6.4.4-linux-amd64
$ chmod +x ./bosh
$ mv bosh-cli-6.4.4-linux-amd64 bosh
$ sudo mv ./bosh /usr/local/bin/bosh
$ bosh 

Step 5- kapp (v0.21.0+) will aid you to deploy cf-for-k8s to your cluster


$ wget -O- https://carvel.dev/install.sh | bash
# or with curl...
$ curl -L https://carvel.dev/install.sh | bash
$ kapp --version

Step 6- ytt (v0.26.0+) will help create templates to deploy cf-for-k8s


$ wget https://github.com/vmware-tanzu/carvel-ytt/releases/download/v0.35.1/ytt-linux-amd64
$ mv ytt-linux-amd64 ytt
$ chmod +x ./ytt
$ sudo mv ./ytt /usr/local/bin/ytt
$ ytt version

Step 7- DockerHub is the image registry used in this guide please make an account if you don’t have one they are free and quickly made.


Username - devopsschools
Password/Token - 

Step 8- Clone cf-for-k8s github repo


git clone https://github.com/cloudfoundry/cf-for-k8s.git && cd cf-for-k8s

Step 9- Install Docker


apt install docker.io

Step 10 – Create a kubernetes cluster of version of v1.20.2


# Review ./deploy/kind/cluster.yml
$ kind create cluster --config=./deploy/kind/cluster.yml --image kindest/node:v1.20.2

# Latest kubernetes cluster but its not working with v1.21.X
$ kind create cluster --config=./deploy/kind/cluster.yml

$ kubectl cluster-info --context kind-kind
$ kubectl config use-context
$ kubectl --context kind-kind get nodes
$ kubectl --context kind-kind get pods --all-namespaces

Step 11 – Generate the yaml used to deploy CF for k8s


$ ./hack/generate-values.sh -d vcap.me > ./cf-install-values.yml

WARNING: The hack scripts are intended for development of cf-for-k8s.
  They are not officially supported product bits.  Their interface and behavior
  may change at any time without notice.

Step 12 – Append the app_registry credentials to your DockerHub registry to the bottom of the ./cf-install-values.yml replacing with your information. You can copy/paste or use the following command.


cat >> cf-install-values.yml << EOL
app_registry:
  hostname: https://index.docker.io/v1/
  repository_prefix: "devopsschools"
  username: "devopsschools"
  password: "d6b938ab-4bf2-4b49-b7c9-ddddddddd"
EOL

Step 13 – There are a few more lines to add to your cf-install-values.yml, like adding a metrics server because KinD doesn’t come with one.


cat >> cf-install-values.yml << EOL
add_metrics_server_components: true
enable_automount_service_account_token: true
metrics_server_prefer_internal_kubelet_address: true
remove_resource_requirements: true
use_first_party_jwt_tokens: true


load_balancer:
  enable: false
EOL

Step 14 – Now, use cf-install-values.yml to render the final Kubernetes template to raw Kubernetes configuration.


$ ytt -f config -f ./cf-install-values.yml > ./cf-for-k8s-rendered.yml

Step 15 – Deploy CF for k8s


You are ready to deploy cf-for-k8s using the ./cf-for-k8s-rendered.yml file created above. Once you deploy it should take around 10 minutes to finish.

$ kapp deploy -a cf -f ./cf-for-k8s-rendered.yml -y
$ kapp list

Step 16 – Validate the deployment & Create and target an organization and space.



Target your CF CLI to point to the new CF instance.

$ cf api --skip-ssl-validation https://api.vcap.me

Set the CF_ADMIN_PASSWORD environment variable to the CF administrative password, stored in the cf_admin_password key in the configuration-values/deployment-values.yml file:

$ CF_ADMIN_PASSWORD="$(bosh interpolate ./cf-install-values.yml --path /cf_admin_password)"

Log into the installation as the admin user.

$ cf auth admin "$CF_ADMIN_PASSWORD"

Enable Docker

$ cf enable-feature-flag diego_docker

A powerful feature provided by CF is multi-tenancy, where you can create a space for a team, an app or whatever your workflow requires.

Create and target an organization and space.

$ cf create-org test-org
$ cf create-space -o test-org test-space
$ cf target -o test-org -s test-space

Step 17 – Deploy an application with cf push


At last you can push the included sample test-node-app.

$ cf push test-node-app -p ./tests/smoke/assets/test-node-app

Or you can push any app you wish just cd into the directory and push the app with the following command.

$ cf push APP-NAME

Once your app stages you can find it in Cloud Foundry with this command.

$ cf apps

The output in the terminal should look something as follows.

Getting apps in org test-org / space test-space as admin...
OK

name            requested state   instances   memory   disk   urls
test-node-app   started           1/1         1G       1G     test-node-app.vcap.me
To see the pods that have applications on your Cloud Foundry instance look in the cf-workloads namespace.

$ kubectl get pods -n cf-workloads

# Access using https
curl -k https://test-node-app.apps.vcap.me

Step 18 – Deploy another application with cf push


$ git clone https://github.com/cloudfoundry-samples/test-app.git
$ cd test-app
$ cf push test-app

# Access using following urls

curl -k https://test-node-app.apps.vcap.me
curl -k https://test-app-grumpy-wallaby-gi.apps.vcap.me
curl -k https://test-app-grumpy-wallaby-gi.apps.vcap.me/env
curl -k https://test-app-grumpy-wallaby-gi.apps.vcap.me/exit
curl -k https://test-app-grumpy-wallaby-gi.apps.vcap.me/index
curl -k https://test-app-grumpy-wallaby-gi.apps.vcap.me/port

Last: Delete the cf-for-k8s deployment & Kind cluster


$ kapp delete -a cf
$ kind delete cluster

Reference

  • https://tanzu.vmware.com/developer/guides/kubernetes/cf4k8s-gs/
  • https://cf-for-k8s.io/docs/
  • https://katacoda.com/cloudfoundry-tutorials/scenarios/trycf
Rajesh Kumar
Follow me
Latest posts by Rajesh Kumar (see all)