add practicies

This commit is contained in:
Pavel Selivanov
2018-07-26 15:13:04 +02:00
parent 530db00034
commit 9ee6d9e3e0
26 changed files with 666 additions and 0 deletions

View File

@@ -0,0 +1,21 @@
# 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

View File

@@ -0,0 +1,5 @@
apiVersion: v1
appVersion: "1.0"
description: A Helm chart for Kubernetes
name: fileshare
version: 0.1.0

View File

@@ -0,0 +1,19 @@
1. Get the application URL by running these commands:
{{- if .Values.ingress.enabled }}
{{- range .Values.ingress.hosts }}
http{{ if $.Values.ingress.tls }}s{{ end }}://{{ . }}{{ $.Values.ingress.path }}
{{- end }}
{{- else if contains "NodePort" .Values.service.type }}
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ template "fileshare.fullname" . }})
export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
echo http://$NODE_IP:$NODE_PORT
{{- else if contains "LoadBalancer" .Values.service.type }}
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
You can watch the status of by running 'kubectl get svc -w {{ template "fileshare.fullname" . }}'
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ template "fileshare.fullname" . }} -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
echo http://$SERVICE_IP:{{ .Values.service.port }}
{{- else if contains "ClusterIP" .Values.service.type }}
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app={{ template "fileshare.name" . }},release={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
echo "Visit http://127.0.0.1:8080 to use your application"
kubectl port-forward $POD_NAME 8080:80
{{- end }}

View File

@@ -0,0 +1,32 @@
{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "fileshare.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 "fileshare.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 "fileshare.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}

View File

@@ -0,0 +1,28 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ template "fileshare.fullname" . }}
labels:
app: {{ template "fileshare.name" . }}
chart: {{ template "fileshare.chart" . }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
data:
default.conf: |
server {
listen 80 default_server;
server_name _;
location / {
return 200 '$hostname\n';
}
location /files {
alias /data;
autoindex on;
client_body_temp_path /tmp;
dav_methods PUT DELETE MKCOL COPY MOVE;
create_full_put_path on;
dav_access user:rw group:rw all:r;
}
}

View File

@@ -0,0 +1,64 @@
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: {{ template "fileshare.fullname" . }}
labels:
app: {{ template "fileshare.name" . }}
chart: {{ template "fileshare.chart" . }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
spec:
replicas: {{ .Values.replicaCount }}
selector:
matchLabels:
app: {{ template "fileshare.name" . }}
release: {{ .Release.Name }}
template:
metadata:
labels:
app: {{ template "fileshare.name" . }}
release: {{ .Release.Name }}
spec:
containers:
- name: {{ .Chart.Name }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
ports:
- name: http
containerPort: 80
protocol: TCP
readinessProbe:
failureThreshold: 3
httpGet:
path: /
port: http
periodSeconds: 10
successThreshold: 1
timeoutSeconds: 1
livenessProbe:
failureThreshold: 3
httpGet:
path: /
port: http
periodSeconds: 10
successThreshold: 1
timeoutSeconds: 1
initialDelaySeconds: 10
volumeMounts:
- name: config
mountPath: /etc/nginx/conf.d/
- name: data
mountPath: /data
resources:
{{ toYaml .Values.resources | indent 12 }}
volumes:
- name: config
configMap:
name: {{ template "fileshare.fullname" . }}
- name: data
{{- if .Values.persistence.enabled }}
persistentVolumeClaim:
claimName: {{ template "fileshare.fullname" . }}
{{- else }}
emptyDir: {}
{{- end -}}

View File

@@ -0,0 +1,24 @@
{{- if .Values.ingress.enabled -}}
{{- $fullName := include "fileshare.fullname" . -}}
{{- $ingressPath := .Values.ingress.path -}}
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: {{ $fullName }}
labels:
app: {{ template "fileshare.name" . }}
chart: {{ template "fileshare.chart" . }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
spec:
rules:
{{- range .Values.ingress.hosts }}
- host: {{ . }}
http:
paths:
- path: {{ $ingressPath }}
backend:
serviceName: {{ $fullName }}
servicePort: http
{{- end }}
{{- end }}

View File

@@ -0,0 +1,17 @@
{{- if and .Values.persistence.enabled -}}
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: {{ template "fileshare.fullname" . }}
labels:
app: {{ template "fileshare.name" . }}
chart: {{ template "fileshare.chart" . }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: {{ .Values.persistence.size | quote }}
{{- end -}}

View File

@@ -0,0 +1,19 @@
apiVersion: v1
kind: Service
metadata:
name: {{ template "fileshare.fullname" . }}
labels:
app: {{ template "fileshare.name" . }}
chart: {{ template "fileshare.chart" . }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
spec:
type: {{ .Values.service.type }}
ports:
- port: {{ .Values.service.port }}
targetPort: http
protocol: TCP
name: http
selector:
app: {{ template "fileshare.name" . }}
release: {{ .Release.Name }}

View File

@@ -0,0 +1,36 @@
# Default values for fileshare.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.
replicaCount: 1
image:
repository: reloadable-nginx
tag: 1.12
pullPolicy: IfNotPresent
persistence:
enabled: true
size: 1Gi
service:
type: ClusterIP
port: 80
ingress:
enabled: true
path: /
hosts:
- my.host.foo
resources: {}
# We usually recommend not to specify default resources and to leave this as a conscious
# choice for the user. This also increases chances charts run on environments with little
# resources, such as Minikube. If you do want to specify resources, uncomment the following
# lines, adjust them as necessary, and remove the curly braces after 'resources:'.
# limits:
# cpu: 100m
# memory: 128Mi
# requests:
# cpu: 100m
# memory: 128Mi

View File

@@ -0,0 +1,10 @@
FROM nginx:1.12
RUN set -ex && \
apt-get update && \
apt-get install -y procps && \
apt-get clean
COPY docker-entrypoint.sh /
ENTRYPOINT ["/docker-entrypoint.sh"]

View File

@@ -0,0 +1,70 @@
#!/usr/bin/env bash
DIR="etc/nginx/"
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m'
log() {
case $1 in
error)
LOG_LEVEL="error"
COLOR=$RED
;;
notice)
LOG_LEVEL="notice"
COLOR=$GREEN
;;
esac
timestamp="$(date +"%Y/%m/%d %H:%M:%S")"
echo -e "$timestamp [$LOG_LEVEL] $0: ${COLOR}$2${NC}"
}
getmd5() {
tar --strip-components=2 -C / -cf - $DIR | md5sum | awk '{print $1}'
}
if [ ! -d $DIR ]; then
log error "/$DIR not found"
exit 1
fi
if ! [ -x "$(command -v nginx)" ]; then
log error "Nginx is not installed"
exit 1
fi
log notice "starting Nginx process..."
nginx
log notice "watching /$DIR for changes..."
checksum_initial=$(getmd5)
trap "exit 0" SIGINT SIGTERM
while true; do
ps aux | grep 'master process nginx' | grep -q -v grep
NGINX_STATUS=$?
if [ $NGINX_STATUS -ne 0 ]; then
log error "Nginx exited. Stopping entrypoint script..."
exit 1
fi
checksum_current=$(getmd5)
if [ "$checksum_initial" != "$checksum_current" ]; then
checksum_initial=$checksum_current
nginx -tq
NGINX_CONF_STATUS=$?
if [ $NGINX_CONF_STATUS -ne 0 ]; then
log error "couldn't reload Nginx due to an error in the config file"
continue
fi
nginx -s reload
log notice "reloaded Nginx config"
fi
sleep 5
done

View File

@@ -0,0 +1,23 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: fileshare
data:
default.conf: |
server {
listen 80 default_server;
server_name _;
location / {
return 200 '$hostname\n';
}
location /files {
alias /data;
autoindex on;
client_body_temp_path /tmp;
dav_methods PUT DELETE MKCOL COPY MOVE;
create_full_put_path on;
dav_access user:rw group:rw all:r;
}
}

View File

@@ -0,0 +1,60 @@
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: fileshare
spec:
replicas: 2
selector:
matchLabels:
app: fileshare
strategy:
rollingUpdate:
maxSurge: 1
maxUnavailable: 1
type: RollingUpdate
template:
metadata:
labels:
app: fileshare
spec:
containers:
- image: reloadable-nginx:1.12
name: nginx
ports:
- containerPort: 80
readinessProbe:
failureThreshold: 3
httpGet:
path: /
port: 80
periodSeconds: 10
successThreshold: 1
timeoutSeconds: 1
livenessProbe:
failureThreshold: 3
httpGet:
path: /
port: 80
periodSeconds: 10
successThreshold: 1
timeoutSeconds: 1
initialDelaySeconds: 10
resources:
requests:
cpu: 100m
memory: 100Mi
limits:
cpu: 100m
memory: 100Mi
volumeMounts:
- name: config
mountPath: /etc/nginx/conf.d
- name: data
mountPath: /data
volumes:
- name: config
configMap:
name: fileshare
- name: data
persistentVolumeClaim:
claimName: fileshare

View File

@@ -0,0 +1,12 @@
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: fileshare
spec:
rules:
- host: my.host.foo
http:
paths:
- backend:
serviceName: fileshare
servicePort: 80

View File

@@ -0,0 +1,10 @@
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: fileshare
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi

View File

@@ -0,0 +1,11 @@
apiVersion: v1
kind: Service
metadata:
name: fileshare
spec:
ports:
- port: 80
targetPort: 80
selector:
app: fileshare
type: ClusterIP

View File

@@ -0,0 +1,14 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: my-configmap
data:
default.conf: |
server {
listen 80 default_server;
server_name _;
location / {
return 200 '$hostname\n';
}
}

View File

@@ -0,0 +1,55 @@
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: my-deployment
spec:
replicas: 2
selector:
matchLabels:
app: my-app
strategy:
rollingUpdate:
maxSurge: 1
maxUnavailable: 1
type: RollingUpdate
template:
metadata:
labels:
app: my-app
spec:
containers:
- image: nginx:1.12
name: nginx
ports:
- containerPort: 80
readinessProbe:
failureThreshold: 3
httpGet:
path: /
port: 80
periodSeconds: 10
successThreshold: 1
timeoutSeconds: 1
livenessProbe:
failureThreshold: 3
httpGet:
path: /
port: 80
periodSeconds: 10
successThreshold: 1
timeoutSeconds: 1
initialDelaySeconds: 10
resources:
requests:
cpu: 100m
memory: 100Mi
limits:
cpu: 100m
memory: 100Mi
volumeMounts:
- name: config
mountPath: /etc/nginx/conf.d/
volumes:
- name: config
configMap:
name: my-configmap

View File

@@ -0,0 +1,48 @@
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: my-deployment
spec:
replicas: 2
selector:
matchLabels:
app: my-app
strategy:
rollingUpdate:
maxSurge: 1
maxUnavailable: 1
type: RollingUpdate
template:
metadata:
labels:
app: my-app
spec:
containers:
- image: nginx:1.12
name: nginx
ports:
- containerPort: 80
readinessProbe:
failureThreshold: 3
httpGet:
path: /
port: 80
periodSeconds: 10
successThreshold: 1
timeoutSeconds: 1
livenessProbe:
failureThreshold: 3
httpGet:
path: /
port: 80
periodSeconds: 10
successThreshold: 1
timeoutSeconds: 1
initialDelaySeconds: 10
resources:
requests:
cpu: 100m
memory: 100Mi
limits:
cpu: 100m
memory: 100Mi

View File

@@ -0,0 +1,24 @@
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: my-deployment
spec:
replicas: 2
selector:
matchLabels:
app: my-app
strategy:
rollingUpdate:
maxSurge: 1
maxUnavailable: 1
type: RollingUpdate
template:
metadata:
labels:
app: my-app
spec:
containers:
- image: nginx:1.12
name: nginx
ports:
- containerPort: 80

View File

@@ -0,0 +1,12 @@
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: my-ingress
spec:
rules:
- host: my.host.foo
http:
paths:
- backend:
serviceName: my-service
servicePort: 80

View File

@@ -0,0 +1,12 @@
apiVersion: v1
kind: Pod
metadata:
name: my-pod
labels:
app: my-app
spec:
containers:
- image: nginx:1.12
name: nginx
ports:
- containerPort: 80

View File

@@ -0,0 +1,10 @@
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: my-claim
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi

View File

@@ -0,0 +1,19 @@
apiVersion: extensions/v1beta1
kind: ReplicaSet
metadata:
name: my-replicaset-2
spec:
replicas: 0
selector:
matchLabels:
app: my-app
template:
metadata:
labels:
app: my-app
spec:
containers:
- image: nginx:1.13
name: nginx
ports:
- containerPort: 80

View File

@@ -0,0 +1,11 @@
apiVersion: v1
kind: Service
metadata:
name: my-service
spec:
ports:
- port: 80
targetPort: 80
selector:
app: my-app
type: ClusterIP