Skip to content

Commit

Permalink
Kubernetes prototype
Browse files Browse the repository at this point in the history
  • Loading branch information
paliarush committed Jan 18, 2019
1 parent 57f8554 commit 6d6a7e4
Show file tree
Hide file tree
Showing 103 changed files with 1,559 additions and 375 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/.vagrant
/.idea
/.composer
/log/*.log
/scripts/.current_nesting_level
/scripts/.current_log_path
Expand Down
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -378,3 +378,15 @@ Note: See [Working with npm](https://www.npmjs.com/package/n#working-with-npm) i
mv ~/.vagrant.d/boxes/{name of your paliarush/ubuntu image}/metadata_url2 ~/.vagrant.d/boxes/{name of your paliarush/ubuntu image}/metadata_url
```

# Kubernetes

Install helm:
`brew install kubernetes-helm` - see [installation guide](https://docs.helm.sh/using_helm/#installing-helm)

Install helm client with `helm init`

To get Helm support in PhpStorm make sure to get v2018.3+

## Manual steps (workarounds)
1. `sudo chmod a+w .` needed to allow write permissions over NFS since users are different on the guest and host
2. `chmod a+x magento/bin/magento`
5 changes: 4 additions & 1 deletion etc/.gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
/*
!/.gitignore
!/docker
!/composer
/composer/*
!/composer/auth.json.dist
!/config.yaml.dist
!/magento2_virtual_host.conf.dist
!/guest
!/guest
!/kubernetes
!/helm
2 changes: 0 additions & 2 deletions etc/config.yaml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ environment:
use_varnish: 0
# [To apply changes: m-reinstall] Possible values: mysql, elasticsearch
search_engine: "mysql"
# [To apply changes: m-clear-cache] Possible values: redis, filesystem
cache_backend: "redis"

magento:
# [To apply changes: m-switch-to-ce -f OR m-switch-to-ee -f]
Expand Down
4 changes: 4 additions & 0 deletions etc/docker/monolith-with-xdebug/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM magento2-monolith:dev

RUN sed -i "s|;zend_extension=xdebug.so|zend_extension=xdebug.so|g" /usr/local/etc/php/conf.d/zz-xdebug-settings.ini
RUN sed -i "s|listen = 0.0.0.0:9001|listen = 0.0.0.0:9002|g" /usr/local/etc/php-fpm.conf
3 changes: 3 additions & 0 deletions etc/docker/monolith/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM paliarush123/minikube-php-fpm:latest

RUN sed -i "s|listen = 0.0.0.0:9000|listen = 0.0.0.0:9001|g" /usr/local/etc/php-fpm.conf
12 changes: 12 additions & 0 deletions etc/helm/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Common backup files
*.swp
*.bak
*.tmp
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
charts/checkout/sources/*
sources/
22 changes: 22 additions & 0 deletions etc/helm/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
5 changes: 5 additions & 0 deletions etc/helm/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apiVersion: v1
appVersion: "1.0"
description: A Helm chart for Kubernetes
name: monolith
version: 0.1.0
21 changes: 21 additions & 0 deletions etc/helm/LICENSE_MIT
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2019

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
75 changes: 75 additions & 0 deletions etc/helm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# Magento Kubernetes components

Install minikube.

Start minikube. And use docker env.

```bash
minikube start
eval $(minikube docker-env)
```

Install helm (cluster should be run to set tiller). [Install guide](https://docs.helm.sh/using_helm/#installing-helm)


## NFS server (optional)

Configure your sources directory as export (/etc/exports) in the NFS server that runs on your host machine. This way containers can mount source code. This is a lot faster than a default VirtualBox shared folder mount. You only have to do this once, the NFS service will load /etc/exports at (re)boot.

NOTE: The Minikube IP can be different after a minikube delete and minikube start command. Make sure that your NFS export contains the correct Minikube IP again.

[More info](http://pietervogelaar.nl/minikube-nfs-mounts)

### Mac OS X
If you do not have python, install it using brew:
```bash
brew install python
```
echo "$(python -c 'import os,sys;print(os.path.realpath(".")')/sources -alldirs -mapall="$(id -u)":"$(id -g))" $(minikube ip)" | sudo tee -a /etc/exports && sudo nfsd restart
Check if the entry is active by executing on your host machine:

```bash
showmount -e 127.0.0.1
```

This should output something like:

```bash
Exports list on 127.0.0.1:
/Absolute/path/to/magento 192.168.99.100
```

There is also variable in values.yml which should be enabled

## Run deployments

Configuration values located in values.yaml

To run all charts execute next command:

```bash
helm install --values values.yaml .
```

(temporary) Magento sources should be cloned to source path in current chart and in checkout subchart as well.

DB password autogenerated in container, to check it list pods:
```bash
kubectl get pods
```

choose one of mysql pods end run bash in it:

```bash
kubectl exec -it release-1-some-mysql-pod bash
```

Observe env variables with prefix MYSQL_

## Clean

To delete releases run:
```
helm delete $(helm list -q)
```

5 changes: 5 additions & 0 deletions etc/helm/charts/checkout/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apiVersion: v1
appVersion: "1.0"
description: A Helm chart for Kubernetes
name: checkout
version: 0.1.0
Binary file added etc/helm/charts/checkout/charts/mysql-0.9.2.tgz
Binary file not shown.
23 changes: 23 additions & 0 deletions etc/helm/charts/checkout/etc/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
events {
worker_connections 1024;
}

http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;

upstream fastcgi_backend {
server 127.0.0.1:9000;
}

server {
listen 80 default_server;
listen [::]:80 default_server;

server_name _;
set $MAGE_ROOT {{.Values.global.checkout.volumeHostPath}};
include {{.Values.global.checkout.volumeHostPath}}/nginx.conf.sample;
}
}
6 changes: 6 additions & 0 deletions etc/helm/charts/checkout/requirements.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
dependencies:
- name: mysql
repository: https://kubernetes-charts.storage.googleapis.com/
version: 0.9.2
digest: sha256:5f1ec2d74a44651865b038da4fb76dc9d5ee04084a1db574c50657ba1b0d96fc
generated: 2019-01-03T00:55:37.077265-08:00
6 changes: 6 additions & 0 deletions etc/helm/charts/checkout/requirements.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
dependencies:
- name: mysql
version: "0.9.2"
appVersion: 5.7.14
repository: "@stable"
alias: checkout-mysql
32 changes: 32 additions & 0 deletions etc/helm/charts/checkout/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "checkout.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "checkout.fullname" -}}
{{- if .Values.fullnameOverride -}}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- $name := default .Chart.Name .Values.nameOverride -}}
{{- if contains $name .Release.Name -}}
{{- .Release.Name | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{- end -}}
{{- end -}}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "checkout.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}
49 changes: 49 additions & 0 deletions etc/helm/charts/checkout/templates/checkout-deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "checkout.fullname" . }}
labels:
app.kubernetes.io/name: {{ include "checkout.name" . }}
helm.sh/chart: {{ include "checkout.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
spec:
selector:
matchLabels:
app.kubernetes.io/name: {{ include "checkout.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
template:
metadata:
labels:
app.kubernetes.io/name: {{ include "checkout.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
spec:
containers:
- name: {{ .Chart.Name }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
ports:
- containerPort: 80
volumeMounts:
- name: {{ .Chart.Name }}-code
mountPath: {{.Values.global.checkout.volumeHostPath}}
- name: {{ .Chart.Name }}-nginx
image: nginx:1.9
volumeMounts:
- name: {{ .Chart.Name }}-code
mountPath: {{.Values.global.checkout.volumeHostPath}}
- name: {{ template "checkout.fullname" . }}-nginx-config-volume
mountPath: /etc/nginx/nginx.conf
subPath: nginx.conf
volumes:
- name: {{ template "checkout.fullname" . }}-nginx-config-volume
configMap:
name: {{ template "checkout.fullname" . }}-nginx-config
- name: {{ .Chart.Name }}-code
{{- if .Values.persistence.nfs.enabled }}
persistentVolumeClaim:
claimName: {{ include "checkout.fullname" . }}-claim
{{- else }}
hostPath:
path: {{.Values.global.checkout.volumeHostPath}}
{{- end -}}
6 changes: 6 additions & 0 deletions etc/helm/charts/checkout/templates/configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: ConfigMap
apiVersion: v1
metadata:
name: {{ template "checkout.fullname" . }}-nginx-config
data:
nginx.conf: {{.Files.Get "etc/nginx.conf" | printf "%s" | indent 4}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{{- if .Values.persistence.nfs.enabled }}
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: {{ include "checkout.fullname" . }}-claim
namespace: default
spec:
storageClassName: standard
accessModes:
- ReadWriteMany
resources:
requests:
storage: 2Gi
{{- end }}
19 changes: 19 additions & 0 deletions etc/helm/charts/checkout/templates/default-sources-volume.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{{- if .Values.persistence.nfs.enabled }}
apiVersion: v1
kind: PersistentVolume
metadata:
name: {{ include "checkout.fullname" . }}-volume
spec:
capacity:
storage: 2Gi
accessModes:
- ReadWriteMany
storageClassName: standard
nfs:
# The address 192.168.99.1 is the Minikube gateway to the host. This way
# not the container IP will be visible by the NFS server on the host machine,
# but the IP address of the `minikube ip` command. You will need to
# grant access to the `minikube ip` IP address.
server: 192.168.99.1
path: {{.Values.global.checkout.volumeHostPath}}
{{- end }}
Loading

0 comments on commit 6d6a7e4

Please sign in to comment.