Helm chartv1.1.0App 7

Modular and transparent LAMP stack chart supporting PHP-FPM, Release Cloning, LoadBalancer, Ingress, SSL and lots more!

About this chart

LAMP

Ever wanted to deploy a LAMP Stack on Kubernetes?

TL;DR;

$ helm install <helm-repo>/lamp

$ helm install stable/lamp

Introduction

This chart bootstraps a LAMP Stack deployment on a Kubernetes cluster using the Helm package manager. It was designed in a very modular and transparent way. Instead of using a custom built docker container running multiple services like apache and php-fpm inside with no control or overwatch of these processes from within kubernetes, this chart takes the approach of using one service per container.

The charts default configurations were made with performance in mind. By default PHP-FPM is enabled and communication between php and mysql as well as apache and php is realized over unix sockets.

By default the chart is exposed to the public via LoadBalancer IP but exposing the chart via an ingress controller is also supported. If a working lego container is configured the chart supports creating lets encrypt certificates.

Setting up your website is easy, you can either use git or svn to copy your repo into the pod or use sftp or webdav and simply transfer your files into the container. If you have a different method of setting up your website, you can manually prepare it inside of an init container before the services start.

Once you've set up your website, you'd like to have separate development environments for testing? Don't worry, with one additional setting you can clone an existing release without downtime using the xtrabackup init container.

Official containers are used wherever possible ( namingly php, apache, mysql, mariadb and percona ) while the use of well established containers was anticipated otherwise ( phpmyadmin/phpmyadmin, atmoz/sftp, openweb/git-sync ) . To provide some of its unique features such as chart cloning and wordpress support some containers had to be newly created. All of those are hosted as automated builds on docker hub - with their respective sources on GitHub (lead4good/init-wp, lead4good/svn-sync, lead4good/webdav, lead4good/xtrabackup).

Prerequisites

  • Kubernetes 1.7+
  • LoadBalancer support or Ingress Controller

Installing the Chart

To install the chart with the release name my-release:

$ helm install --name my-release <helm-repo>/lamp

$ helm install --name my-release stable/lamp The command deploys the LAMP chart on the Kubernetes cluster in the default configuration. The configuration section lists the parameters that can be configured during installation.

Tip: List all releases using helm list

Uninstalling the Chart

To uninstall/delete the my-release deployment:

$ helm delete my-release

The command removes all the Kubernetes components associated with the chart and deletes the release.

Examples

To try out one of the examples. you can run, e.g. for wordpress:

$ helm install -f examples/wordpress.yaml --name wordpress <helm-repo>/lamp

$ helm install -f examples/wordpress.yaml --name wordpress stable/lamp Currently you can try the following examples:

  • examples/wordpress.yaml
  • examples/wordpress-ingress-ssl.yaml
  • examples/wordpress-php-ini.yaml
  • examples/drupal.yaml
  • examples/joomla.yaml
  • examples/joomla.yaml
  • examples/owncloud.yaml
  • examples/nextcloud.yaml

Configuration

The following tables list the configurable parameters of the LAMP chart and their default values.

You can specify each of the parameters using the --set key=value[,key=value] argument to helm install. For example,

You can specify each of the parameters using the `--set key=value[,key=value]` argument to `helm install`. For example,
$ helm install --name my-release \
  --set init.clone.release=my-first-release-lamp,php.sockets=false,php.oldHTTPRoot=/var/www/my-website.com \
    <helm-repo>/lamp
$ helm install --name my-release \

The above command sets up the chart to create its persistent contents by cloning its content from my-first-release-lamp, sets PHP socket communication to false and sets an old http root to compensate for absolute path file links

Alternatively, a YAML file that specifies the values for the above parameters can be provided while installing the chart. For example,

$ helm install --name my-release -f values.yaml <helm-repo>/lamp

$ helm install --name my-release -f values.yaml stable/lamp

Tip: You can use the default values.yaml file as a template

Manually preparing the webroot and database

The manual init container enables you to manually pull a websites backup from somewhere and set it up inside the container before the chart is deployed. Set init.manually.enabled to true and connect to the container by replacing example-com-lamp and executing

$ kubectl exec -it \
  $(kubectl get pods -l app=example-com-lamp --output=jsonpath={.items..metadata.name}) \
  -c init-manually /bin/bash

The container has the document root mounted at /var/www/html and the database directory mounted at /var/lib/mysql . The default manual init container is derived from the official mysql container and can create and startup a mysql db by setting the necessary environment variables and then executing

$ /entrypoint.sh mysqld &

If another flavor of DB is used (mariadb or percona) then the image needs to be pointing to the right container.

After setting up your DB backup you can stop the database by executing

$ mysqladmin -uroot -p$MYSQL_ROOT_PASSWORD shutdown

Now copy all necessary files into the web directory, but do not forget to recursively chown the webroot to the www-data user ( id 33 ) by executing

$ chown -R 33:33 /var/www/html

Once everything is setup stopping the init container is done by executing

$ im-done
ParameterDescriptionDefault
init.manually.enabledEnables container for manual initializationfalse
init.manually.repositoryContainers imagelead4good/init-wp
init.manually.tagContainers image taglatest
init.manually.pullPolicyImage pull policyAlways

Cloning charts

If init.clone.release is set to the fullname of an existing, already running LAMP chart (e.g. example-com-lamp), the persistent storage of that chart (web files and db) will be copied to this charts persistent storage. It is mandatory that both database containers are of the same type (mysql, mariadb or percona). Mixing them will not work.

ParameterDescriptionDefault
init.clone.releaseFullname of the release to cloneempty
init.clone.hostPathIf the release to clone uses hostPath instead of PVC, set it here. This will only work if both releases are deployed on the same nodeempty

Init Containers Resources

| init.resources | init containers resource requests/limits | resources |

PHP and HTTPD Containers

The PHP container is at the heart of the LAMP chart. By default, the LAMP chart uses the official PHP container from docker hub. You can also use your own PHP container, which needs to have the official PHP container at its base. FPM is enabled by default, this creates an additional HTTPD container which routes PHP request via FCGI to the PHP container. Set php.fpmEnabled to false to work with the official php:apache image.

Note: If you are using a custom container, be sure to use the official php:apache or php:fpm containers at its base and set php.fpmEnabled accordingly

ParameterDescriptionDefault
php.repositorydefault php imagephp
php.tagdefault php image tag7-fpm-alpine
php.pullPolicyImage pull policyAlways
php.fpmEnabledEnables FPM functionality, be sure to disable if working with a custom repository based on the apache tagtrue
php.socketsIf FPM is enabled, enables communication between HTTPD and PHP via sockets instead of TCPtrue
php.oldHTTPRootAdditionally mounts the webroot at php.oldHTTPRoot to compensate for absolute path file linksempty
php.iniadditional PHP config values, see examples on how to useempty
php.fpmaddditonal PHP FPM config valuesempty
php.copyRootif true, copies the containers web root /var/www/html into persistent storage. This must be enabled, if the container already comes with files installed to /var/www/htmlfalse
php.persistentSubpathsinstead of enabling persistence for the whole webroot, only subpaths of webroot can be enabled for persistence. Have a look at the nextcloud example to see how it worksempty
php.resourcesPHP container resource requests/limitsresources
httpd.repositorydefault httpd image if fpm is enabledhttpd
httpd.tagdefault httpd image tag2.4-alpine
httpd.resourcesHTTPD container resource requests/limitsresources

MySQL Container

The MySQL container is disabled by default, any container with the base image of the official mysql, mariadb or percona should work.

ParameterDescriptionDefault
mysql.rootPasswordSets the MySQL root password, enables MySQL service if not emptyempty
mysql.userMySQL userempty
mysql.passwordMySQL user passwordempty
mysql.databaseMySQL user databaseempty
mysql.repositoryMySQL image - choose one of the official mysql, mariadb or percona imagesmysql
mysql.tagMySQL image tag5.7
mysql.imagePullPolicyImage pull policyAlways
mysql.socketsEnables communication between MySQL and PHP via sockets instead of TCPtrue
mysql.resourcesResource requests/limitsresources

SFTP Container

SFTP is an instance of the atmoz/sftp container, through which you can access the webroot.

Note: The webroot is located in the subfolder of the sftp users home directory so putting files into the webroot via sftp have to be put to the web subfolder and the put command will fail if you upload to the root directory since writing permissions are disabled there.

Note: using a different image than the default atmoz/sftp will most probably not work since the containers startup command is overwritten to be able to configure the sftp user, you may however change the tag to a different version without any problems

ParameterDescriptionDefault
sftp.repositorydefault sftp imageatmoz/sftp
sftp.tagdefault sftp image tagalpine
sftp.enabledEnables sftp servicefalse
sftp.portPort to advertise service in LoadBalancer mode22
sftp.nodePortPort to advertise service in Ingress modeempty
sftp.userSFTP Userempty
sftp.passwordSFTP Passwordempty
sftp.resourcesresource requests/limitsresources

WebDAV Container

An instance of WebDAV, through which you can access the webroot.

ParameterDescriptionDefault
webdav.enabledEnables webdav servicefalse
webdav.portPort to advertise service in LoadBalancer mode8001
webdav.subdomainSubdomain to advertise service on if ingress is enabledwebdav
webdav.userWebDAV Userempty
webdav.passwordWebDAV Passwordempty
webdav.resourcesresource requests/limitsresources

Git Container

If Git is enabled, the contents of the specified repository will be synchronized every git.wait seconds to the web root. The web root needs to be empty otherwise the container will fail exit.

Note: You should not combine SFTP or WebDAV with the Git container since this might cause confusion if someone edits a file via SFTP just to find out that its changes got reverted by the Git sync process

ParameterDescriptionDefault
git.enabledEnables Git servicefalse
git.repoURLGit Repository URLempty
git.branchRepository branch to syncmaster
git.revisionRevision to syncFETCH_HEAD
git.waitTime between Git syncs30
git.resourcesresource requests/limitsresources

SVN Container

If SVN is enabled, the contents of the specifie

Deploy lamp with OpenTenant

Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has lamp on a Hetzner server. Change the host, add apps from the marketplace, then copy the generated files. Providers and prices are samples, and nothing here is sent anywhere.

  1. Pick a serverConnect Hetzner, OVHcloud or AWS. The builder starts on Hetzner, the cheapest sample rate.
  2. Place the chartlamp is pinned at v1.1.0 in opentenant.yaml. Drag more apps from the marketplace onto a rack.
  3. ApplySave opentenant.yaml and main.tf from the console, then run the commands below.
# opentenant.yaml, main.tf and dns.tf come from the builder below
opentenant validate opentenant.yaml
terraform init && terraform apply