Skip to content
This repository was archived by the owner on Oct 1, 2020. It is now read-only.

Commit 6d6a7e4

Browse files
committed
Kubernetes prototype
1 parent 57f8554 commit 6d6a7e4

File tree

103 files changed

+1559
-375
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+1559
-375
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/.vagrant
22
/.idea
3+
/.composer
34
/log/*.log
45
/scripts/.current_nesting_level
56
/scripts/.current_log_path

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,3 +378,15 @@ Note: See [Working with npm](https://www.npmjs.com/package/n#working-with-npm) i
378378
mv ~/.vagrant.d/boxes/{name of your paliarush/ubuntu image}/metadata_url2 ~/.vagrant.d/boxes/{name of your paliarush/ubuntu image}/metadata_url
379379
```
380380

381+
# Kubernetes
382+
383+
Install helm:
384+
`brew install kubernetes-helm` - see [installation guide](https://docs.helm.sh/using_helm/#installing-helm)
385+
386+
Install helm client with `helm init`
387+
388+
To get Helm support in PhpStorm make sure to get v2018.3+
389+
390+
## Manual steps (workarounds)
391+
1. `sudo chmod a+w .` needed to allow write permissions over NFS since users are different on the guest and host
392+
2. `chmod a+x magento/bin/magento`

etc/.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
/*
22
!/.gitignore
3+
!/docker
34
!/composer
45
/composer/*
56
!/composer/auth.json.dist
67
!/config.yaml.dist
78
!/magento2_virtual_host.conf.dist
8-
!/guest
9+
!/guest
10+
!/kubernetes
11+
!/helm

etc/config.yaml.dist

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ environment:
4141
use_varnish: 0
4242
# [To apply changes: m-reinstall] Possible values: mysql, elasticsearch
4343
search_engine: "mysql"
44-
# [To apply changes: m-clear-cache] Possible values: redis, filesystem
45-
cache_backend: "redis"
4644

4745
magento:
4846
# [To apply changes: m-switch-to-ce -f OR m-switch-to-ee -f]
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
FROM magento2-monolith:dev
2+
3+
RUN sed -i "s|;zend_extension=xdebug.so|zend_extension=xdebug.so|g" /usr/local/etc/php/conf.d/zz-xdebug-settings.ini
4+
RUN sed -i "s|listen = 0.0.0.0:9001|listen = 0.0.0.0:9002|g" /usr/local/etc/php-fpm.conf

etc/docker/monolith/Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
FROM paliarush123/minikube-php-fpm:latest
2+
3+
RUN sed -i "s|listen = 0.0.0.0:9000|listen = 0.0.0.0:9001|g" /usr/local/etc/php-fpm.conf

etc/helm/.gitignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Common backup files
2+
*.swp
3+
*.bak
4+
*.tmp
5+
*~
6+
# Various IDEs
7+
.project
8+
.idea/
9+
*.tmproj
10+
.vscode/
11+
charts/checkout/sources/*
12+
sources/

etc/helm/.helmignore

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Patterns to ignore when building packages.
2+
# This supports shell glob matching, relative path matching, and
3+
# negation (prefixed with !). Only one pattern per line.
4+
.DS_Store
5+
# Common VCS dirs
6+
.git/
7+
.gitignore
8+
.bzr/
9+
.bzrignore
10+
.hg/
11+
.hgignore
12+
.svn/
13+
# Common backup files
14+
*.swp
15+
*.bak
16+
*.tmp
17+
*~
18+
# Various IDEs
19+
.project
20+
.idea/
21+
*.tmproj
22+
.vscode/

etc/helm/Chart.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
apiVersion: v1
2+
appVersion: "1.0"
3+
description: A Helm chart for Kubernetes
4+
name: monolith
5+
version: 0.1.0

etc/helm/LICENSE_MIT

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2019
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

etc/helm/README.md

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# Magento Kubernetes components
2+
3+
Install minikube.
4+
5+
Start minikube. And use docker env.
6+
7+
```bash
8+
minikube start
9+
eval $(minikube docker-env)
10+
```
11+
12+
Install helm (cluster should be run to set tiller). [Install guide](https://docs.helm.sh/using_helm/#installing-helm)
13+
14+
15+
## NFS server (optional)
16+
17+
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.
18+
19+
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.
20+
21+
[More info](http://pietervogelaar.nl/minikube-nfs-mounts)
22+
23+
### Mac OS X
24+
If you do not have python, install it using brew:
25+
```bash
26+
brew install python
27+
```
28+
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
29+
Check if the entry is active by executing on your host machine:
30+
31+
```bash
32+
showmount -e 127.0.0.1
33+
```
34+
35+
This should output something like:
36+
37+
```bash
38+
Exports list on 127.0.0.1:
39+
/Absolute/path/to/magento 192.168.99.100
40+
```
41+
42+
There is also variable in values.yml which should be enabled
43+
44+
## Run deployments
45+
46+
Configuration values located in values.yaml
47+
48+
To run all charts execute next command:
49+
50+
```bash
51+
helm install --values values.yaml .
52+
```
53+
54+
(temporary) Magento sources should be cloned to source path in current chart and in checkout subchart as well.
55+
56+
DB password autogenerated in container, to check it list pods:
57+
```bash
58+
kubectl get pods
59+
```
60+
61+
choose one of mysql pods end run bash in it:
62+
63+
```bash
64+
kubectl exec -it release-1-some-mysql-pod bash
65+
```
66+
67+
Observe env variables with prefix MYSQL_
68+
69+
## Clean
70+
71+
To delete releases run:
72+
```
73+
helm delete $(helm list -q)
74+
```
75+

etc/helm/charts/checkout/Chart.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
apiVersion: v1
2+
appVersion: "1.0"
3+
description: A Helm chart for Kubernetes
4+
name: checkout
5+
version: 0.1.0
8.62 KB
Binary file not shown.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
events {
2+
worker_connections 1024;
3+
}
4+
5+
http {
6+
include mime.types;
7+
default_type application/octet-stream;
8+
sendfile on;
9+
keepalive_timeout 65;
10+
11+
upstream fastcgi_backend {
12+
server 127.0.0.1:9000;
13+
}
14+
15+
server {
16+
listen 80 default_server;
17+
listen [::]:80 default_server;
18+
19+
server_name _;
20+
set $MAGE_ROOT {{.Values.global.checkout.volumeHostPath}};
21+
include {{.Values.global.checkout.volumeHostPath}}/nginx.conf.sample;
22+
}
23+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
dependencies:
2+
- name: mysql
3+
repository: https://kubernetes-charts.storage.googleapis.com/
4+
version: 0.9.2
5+
digest: sha256:5f1ec2d74a44651865b038da4fb76dc9d5ee04084a1db574c50657ba1b0d96fc
6+
generated: 2019-01-03T00:55:37.077265-08:00
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
dependencies:
2+
- name: mysql
3+
version: "0.9.2"
4+
appVersion: 5.7.14
5+
repository: "@stable"
6+
alias: checkout-mysql
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{{/* vim: set filetype=mustache: */}}
2+
{{/*
3+
Expand the name of the chart.
4+
*/}}
5+
{{- define "checkout.name" -}}
6+
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
7+
{{- end -}}
8+
9+
{{/*
10+
Create a default fully qualified app name.
11+
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
12+
If release name contains chart name it will be used as a full name.
13+
*/}}
14+
{{- define "checkout.fullname" -}}
15+
{{- if .Values.fullnameOverride -}}
16+
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}}
17+
{{- else -}}
18+
{{- $name := default .Chart.Name .Values.nameOverride -}}
19+
{{- if contains $name .Release.Name -}}
20+
{{- .Release.Name | trunc 63 | trimSuffix "-" -}}
21+
{{- else -}}
22+
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
23+
{{- end -}}
24+
{{- end -}}
25+
{{- end -}}
26+
27+
{{/*
28+
Create chart name and version as used by the chart label.
29+
*/}}
30+
{{- define "checkout.chart" -}}
31+
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
32+
{{- end -}}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: {{ include "checkout.fullname" . }}
5+
labels:
6+
app.kubernetes.io/name: {{ include "checkout.name" . }}
7+
helm.sh/chart: {{ include "checkout.chart" . }}
8+
app.kubernetes.io/instance: {{ .Release.Name }}
9+
app.kubernetes.io/managed-by: {{ .Release.Service }}
10+
spec:
11+
selector:
12+
matchLabels:
13+
app.kubernetes.io/name: {{ include "checkout.name" . }}
14+
app.kubernetes.io/instance: {{ .Release.Name }}
15+
template:
16+
metadata:
17+
labels:
18+
app.kubernetes.io/name: {{ include "checkout.name" . }}
19+
app.kubernetes.io/instance: {{ .Release.Name }}
20+
spec:
21+
containers:
22+
- name: {{ .Chart.Name }}
23+
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
24+
imagePullPolicy: {{ .Values.image.pullPolicy }}
25+
ports:
26+
- containerPort: 80
27+
volumeMounts:
28+
- name: {{ .Chart.Name }}-code
29+
mountPath: {{.Values.global.checkout.volumeHostPath}}
30+
- name: {{ .Chart.Name }}-nginx
31+
image: nginx:1.9
32+
volumeMounts:
33+
- name: {{ .Chart.Name }}-code
34+
mountPath: {{.Values.global.checkout.volumeHostPath}}
35+
- name: {{ template "checkout.fullname" . }}-nginx-config-volume
36+
mountPath: /etc/nginx/nginx.conf
37+
subPath: nginx.conf
38+
volumes:
39+
- name: {{ template "checkout.fullname" . }}-nginx-config-volume
40+
configMap:
41+
name: {{ template "checkout.fullname" . }}-nginx-config
42+
- name: {{ .Chart.Name }}-code
43+
{{- if .Values.persistence.nfs.enabled }}
44+
persistentVolumeClaim:
45+
claimName: {{ include "checkout.fullname" . }}-claim
46+
{{- else }}
47+
hostPath:
48+
path: {{.Values.global.checkout.volumeHostPath}}
49+
{{- end -}}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
kind: ConfigMap
2+
apiVersion: v1
3+
metadata:
4+
name: {{ template "checkout.fullname" . }}-nginx-config
5+
data:
6+
nginx.conf: {{.Files.Get "etc/nginx.conf" | printf "%s" | indent 4}}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{{- if .Values.persistence.nfs.enabled }}
2+
kind: PersistentVolumeClaim
3+
apiVersion: v1
4+
metadata:
5+
name: {{ include "checkout.fullname" . }}-claim
6+
namespace: default
7+
spec:
8+
storageClassName: standard
9+
accessModes:
10+
- ReadWriteMany
11+
resources:
12+
requests:
13+
storage: 2Gi
14+
{{- end }}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{{- if .Values.persistence.nfs.enabled }}
2+
apiVersion: v1
3+
kind: PersistentVolume
4+
metadata:
5+
name: {{ include "checkout.fullname" . }}-volume
6+
spec:
7+
capacity:
8+
storage: 2Gi
9+
accessModes:
10+
- ReadWriteMany
11+
storageClassName: standard
12+
nfs:
13+
# The address 192.168.99.1 is the Minikube gateway to the host. This way
14+
# not the container IP will be visible by the NFS server on the host machine,
15+
# but the IP address of the `minikube ip` command. You will need to
16+
# grant access to the `minikube ip` IP address.
17+
server: 192.168.99.1
18+
path: {{.Values.global.checkout.volumeHostPath}}
19+
{{- end }}

0 commit comments

Comments
 (0)