Skip to content
This repository was archived by the owner on Jul 18, 2024. It is now read-only.

Update details on the volumes. #23

Merged
merged 1 commit into from
Oct 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 0 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,6 @@ Simple demonstration of a set of NGINX and PHP containers deployed to the IBM Bl

This shows several basic concepts for deploying a multi-container deployment of NGINX & PHP cluster to Kubernetes and exposing them as services. More complex approaches might use Helm or more sophisticated build and deploy approaches that deploy on commit to a GitHub repo.

It covers these baseline features and scenarios:
- [ ] Provides a script [`scripts/setup-infrastructure.sh`](scripts/setup-infrastructure.sh) that is a placeholder to deploy a Kubernetes cluster and provision the MySQL, Redis, and Memcached services from Bluemix. As an alternative, see the Bluemix [configuration page](docs/INITIAL-SETUP.md) for the UI instructions.
- [x] Provides a script [`scripts/build-containers.sh`](scripts/build-containers.sh) that starts with a supported base PHP 5.6 image, injects custom code, runs Composer, tags and pushes the image to a Bluemix Container Registry.
- [x] Provides a script [`scripts/deploy-containers.sh`](scripts/deploy-containers.sh) to deploy a set of 4 containers (1 NGINX container, 2 PHP-FPM containers, 1 PHP-CLI) from those images and mounts a shared volume to the 3 PHP containers.
- [x] Connects the 3 PHP containers to a MySQL-as-a-Service on startup.
- [x] Connects the 3 PHP containers to a Redis-as-a-Service on startup.
- [x] Connects the 3 PHP containers to a Memcached-as-a-Service on startup.
- [x] Exposes a load balanced endpoint that takes an HTTP POST request and routes it through NGINX to the PHP containers, which saves data in the MySQL and Redis databases, stores it in Memcached, and writes a file to the shared file system.
- [x] Exposes a load balanced endpoint [`app/read.php`](scripts/docker/php-fpm/app/read.php) that takes an HTTP GET request and routes it through NGINX to the PHP containers, which retrieves data in the MySQL and Redis databases, retrieves data from Memcached, and reads a file from the shared file system.
- [x] Exposes a load balanced endpoint [`app/create.php`](scripts/docker/php-fpm/app/create.php) that takes an HTTP POST request and routes it through NGINX to the PHP containers, which creates data in the MySQL and Redis databases, caches data from Memcached, and creates a file on the shared file system.
- [x] Exposes a load balanced endpoint [`app/delete.php`](scripts/docker/php-fpm/app/create.php) that takes an HTTP DELETE request and routes it through NGINX to the PHP containers, which deletes data in the MySQL and Redis databases, clears data from Memcached, and deletes a file from the shared file system.
- [ ] Builds and redeploys new containers with zero downtime on GitHub push.
- [x] Provides a script [`scripts/destroy-containers.sh`](scripts/destroy-containers.sh) to stop and remove the containers (but not the storage volume).
- [ ] Provides a script [`scripts/destroy-infrastructure.sh`](scripts/setup-infrastructure.sh) that is a placeholder to destroy a Kubernetes cluster and deprovision the MySQL, Redis, and Memcached services from Bluemix.


# One time Container Service and Bluemix services setup
See the Container Service Kubernetes and Bluemix services (MySQL, Redis, Memcached) [configuration instructions](docs/INITIAL-SETUP.md).

Expand Down
15 changes: 14 additions & 1 deletion docs/DEPLOY-CONTAINERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Now that the Kubernetes cluster and MySQL, Redis, and Memcached services have be
- The [`scripts/docker/php-cli/Dockerfile`](../scripts/docker/php-cli/Dockerfile) provides the steps to build a custom PHP CLI image based on the latest public image. It installs prerequisite packages, configures and builds the MySQL, Redis, and Memcached extensions, copies the custom application code over, runs Composer, and sets up read/write access to the storage volume for the PHP-FPM process which does not run as root.

## Review the Kubernetes container deployment configuration files
- The [`scripts/kubernetes/persistent-volumes.yaml`](../scripts/kubernetes/persistent-volumes.yaml) files defines a 20 GB storage volume that can be mounted by many containers (`ReadWriteMany`). The containers then reference this file in their own configuration files.
- The [`scripts/kubernetes/persistent-volumes.yaml`](../scripts/kubernetes/persistent-volumes.yaml) files defines three 10 GB storage volume that can be mounted by many containers (`ReadWriteMany`). The containers then reference these volumes in their own configuration files.
- The [`scripts/kubernetes/php-fpm.yaml`](../scripts/kubernetes/php-fpm.yaml) file describes the pod/deployment for the PHP-FPM containers. It specifies how many containers from the given image and tag to start (2, for now), what port to listen on, the environment variables that map to the service credentials, and where to mount the storage volume.
- Similarly The [`scripts/kubernetes/nginx.yaml`](../scripts/kubernetes/nginx.yaml) file describes the pod/deployment for the NGINX containers. It specifies how many containers from the given image and tag to start (1, for now), what port to listen on, the environment variables that map to the service credentials, and where to mount the storage volume.
- Finally, the [`scripts/kubernetes/php-cli.yaml`](../scripts/kubernetes/php-cli.yaml) configures the pool of CLI workers that may be polling a database or queue for messages. It also maps the environment variables and storage volume, but does not expose a service for inbound network access.
Expand All @@ -16,7 +16,20 @@ Now that the Kubernetes cluster and MySQL, Redis, and Memcached services have be
Log into Bluemix and the Container Registry. Make sure your target organization and space is set. If you haven't already installed the Container Registry plugin for the `bx` CLI:

```bash
# Configure the plugin if you haven't yet
bx plugin install container-registry -r Bluemix
bx login -a https://api.ng.bluemix.net
bx cs init
bx cs cluster-config $CLUSTER_NAME

# Configure kubectl
export KUBECONFIG=/Users/$USER_HOME_DIR/.bluemix/plugins/container-service/clusters/$CLUSTER_NAME/kube-config-$DATA_CENTER-$CLUSTER_NAME.yml

# Confirm cluster is ready
kubectl get nodes

# Run the dashboard which will be available on http://127.0.0.1:8001/ui
kubectl proxy
```

Then run this script to build the containers and push them to your registry:
Expand Down
16 changes: 16 additions & 0 deletions docs/FEATURE-LIST.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
## Feature list

It covers these baseline features and scenarios:
- [ ] Provides a script [`scripts/setup-infrastructure.sh`](scripts/setup-infrastructure.sh) that is a placeholder to deploy a Kubernetes cluster and provision the MySQL, Redis, and Memcached services from Bluemix. As an alternative, see the Bluemix [configuration page](docs/INITIAL-SETUP.md) for the UI instructions.
- [x] Provides a script [`scripts/build-containers.sh`](scripts/build-containers.sh) that starts with a supported base PHP 5.6 image, injects custom code, runs Composer, tags and pushes the image to a Bluemix Container Registry.
- [x] Provides a script [`scripts/deploy-containers.sh`](scripts/deploy-containers.sh) to deploy a set of 4 containers (1 NGINX container, 2 PHP-FPM containers, 1 PHP-CLI) from those images and mounts a shared volume to the 3 PHP containers.
- [x] Connects the 3 PHP containers to a MySQL-as-a-Service on startup.
- [x] Connects the 3 PHP containers to a Redis-as-a-Service on startup.
- [x] Connects the 3 PHP containers to a Memcached-as-a-Service on startup.
- [x] Exposes a load balanced endpoint that takes an HTTP POST request and routes it through NGINX to the PHP containers, which saves data in the MySQL and Redis databases, stores it in Memcached, and writes a file to the shared file system.
- [x] Exposes a load balanced endpoint [`app/read.php`](scripts/docker/php-fpm/app/read.php) that takes an HTTP GET request and routes it through NGINX to the PHP containers, which retrieves data in the MySQL and Redis databases, retrieves data from Memcached, and reads a file from the shared file system.
- [x] Exposes a load balanced endpoint [`app/create.php`](scripts/docker/php-fpm/app/create.php) that takes an HTTP POST request and routes it through NGINX to the PHP containers, which creates data in the MySQL and Redis databases, caches data from Memcached, and creates a file on the shared file system.
- [x] Exposes a load balanced endpoint [`app/delete.php`](scripts/docker/php-fpm/app/create.php) that takes an HTTP DELETE request and routes it through NGINX to the PHP containers, which deletes data in the MySQL and Redis databases, clears data from Memcached, and deletes a file from the shared file system.
- [ ] Builds and redeploys new containers with zero downtime on GitHub push.
- [x] Provides a script [`scripts/destroy-containers.sh`](scripts/destroy-containers.sh) to stop and remove the containers (but not the storage volume).
- [ ] Provides a script [`scripts/destroy-infrastructure.sh`](scripts/setup-infrastructure.sh) that is a placeholder to destroy a Kubernetes cluster and deprovision the MySQL, Redis, and Memcached services from Bluemix.
32 changes: 16 additions & 16 deletions docs/INITIAL-SETUP.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
## Provision a Kubernetes cluster on the IBM Bluemix Container Service
- Create a paid Bluemix account, and log into the Bluemix dashboard.
- Choose Containers from the left hand hamburger navigation.
![](img/1-hamburger.png)

![](img/1-hamburger.png)

- Click the Create cluster button.

![](img/2-create-cluster.png)
![](img/2-create-cluster.png)

- Select the Standard type of cluster (this allows for storage volumes) and Create.

![](img/3-standard-cluster.png)
![](img/3-standard-cluster.png)

- Going back to the Dashboard from the navigation, you'll see your cluster.

- Click on it to see the cluster Overview.

![](img/4-overview.png)
![](img/4-overview.png)

- Click on Worker Nodes to get details on your worker nodes.

![](img/5-worker-nodes.png)
![](img/5-worker-nodes.png)

- It will take time for the cluster to complete provisioning, so go get some coffee.

## Connect to your Kubernetes cluster from your workstation
- Click on the Access link to download and configure the `bx` and `kubectl` CLIs. Kubectl version >=1.7.6 is required.

![](img/6-access.png)
![](img/6-access.png)

- Run the configuration commands, making sure that the `$KUBECONFIG` variable path is indeed correct (it may not reflect your actual home directory).
- You can then use `kubectl` or the `kubectl proxy` dashboard web UI that starts on localhost to inspect your Kubernetes environment.
Expand All @@ -36,15 +36,15 @@
- You can do this with the `bx` command too, but I prefer to work with the dashboard as it's a one time setup operation with several options.
- Go to the hamburger navigation again and choose Data & Analytics.

![](img/7-hamburger-data-analytics.png)
![](img/7-hamburger-data-analytics.png)

- Click "Create"

![](img/8-create-data-analytics.png)
![](img/8-create-data-analytics.png)

- You have a choice of two MySQL-as-a-Service providers, Compose and ClearDB. Compose is the preferred option, but ClearDB is quicker to get running with for a PoC.

![](img/9-create-mysql-service.png)
![](img/9-create-mysql-service.png)

- Take note of the credentials, and save them in a `scripts/kubernetes/secrets/service-credentials.txt` file you copy from [`scripts/kubernetes/secrets/service-credentials.txt.tpl`](../scripts/kubernetes/secrets/service-credentials.txt.tpl).
- The Bluemix Container Service offers a way to autobind credentials, but using a secret from this credentials file gives us the option to use services in another organization and space and/or start it up later as its own pod.
Expand All @@ -53,30 +53,30 @@
- You can do this with the `bx` command too, but I prefer to work with the dashboard as it's a one time setup operation with several options.
- Go to the hamburger navigation again and choose Data & Analytics.

![](img/7-hamburger-data-analytics.png)
![](img/7-hamburger-data-analytics.png)

- Click "Create"

![](img/8-create-data-analytics.png)
![](img/8-create-data-analytics.png)

- You have a choice of two Redis-as-a-Service providers, Compose and Redis Cloud. Compose is the preferred option, but Redis Cloud has more plan options.
- Take note of the credentials, and save them in `scripts/kubernetes/secrets/service-credentials.txt`.


![](img/10-create-redis-service.png)
![](img/10-create-redis-service.png)

## Provision and bind a Memcached-as-a-Service
- You can do this with the `bx` command too, but I prefer to work with the dashboard as it's a one time setup operation with several options.
- Go to the hamburger navigation again and choose Data & Analytics.

![](img/7-hamburger-data-analytics.png)
![](img/7-hamburger-data-analytics.png)

- Click "Create"

![](img/8-create-data-analytics.png)
![](img/8-create-data-analytics.png)

- Choose Memcached from Redis Cloud.

![](img/11-create-memcached-service.png)
![](img/11-create-memcached-service.png)

- Take note of the credentials, and save them in `scripts/kubernetes/secrets/service-credentials.txt`.
6 changes: 3 additions & 3 deletions scripts/kubernetes/persistent-volumes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ spec:
- ReadWriteMany
resources:
requests:
storage: 5Gi
storage: 10Gi
---
apiVersion: v1
kind: PersistentVolumeClaim
Expand All @@ -19,7 +19,7 @@ spec:
- ReadWriteMany
resources:
requests:
storage: 5Gi
storage: 10Gi
---
apiVersion: v1
kind: PersistentVolumeClaim
Expand All @@ -30,4 +30,4 @@ spec:
- ReadWriteMany
resources:
requests:
storage: 5Gi
storage: 10Gi