Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kubernetes-4 #8

Merged
merged 4 commits into from
Nov 17, 2023
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
999 changes: 960 additions & 39 deletions README.md

Large diffs are not rendered by default.

Binary file added img/Screenshot_20231024_232101.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/Screenshot_20231025_142253.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/Screenshot_20231025_192152.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/Screenshot_20231026_172236.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/Screenshot_20231029_154520.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/Screenshot_20231029_155002.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/Screenshot_20231029_170607.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/Screenshot_20231029_170717.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/Screenshot_20231029_170840.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/Screenshot_20231029_171848.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/Screenshot_20231030_163800.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/Screenshot_20231030_163925.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/Screenshot_20231030_164645.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/Screenshot_20231030_175352.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/Screenshot_20231031_080044.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/Screenshot_20231031_125718.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/Screenshot_20231031_145820.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/troubleshooting-kubernetes.ru_ru.v2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions kubernetes/Charts/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
!gitlab-omnibus/templates/gitlab-config.yaml
!gitlab-omnibus/templates/gitlab/gitlab-svc.yaml
!gitlab-omnibus/templates/ingress/gitlab-ingress.yaml
gitlab/
157 changes: 157 additions & 0 deletions kubernetes/Charts/.gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
image: alpine/helm:latest

stages:
- test
- staging
- production

test:
stage: test
image:
name: alpine/helm
entrypoint: ["/bin/sh","-c"]
variables:
KUBE_CONTEXT: 23f03013e37f/reddit-deploy:reddit-deploy
KUBE_NAMESPACE: test
environment: test
script:
- install_dependencies
- ensure_namespace
- delete
- deploy
only:
- branches
except:
- triggers

staging:
stage: staging
variables:
KUBE_CONTEXT: 23f03013e37f/reddit-deploy:reddit-deploy
KUBE_NAMESPACE: staging
environment:
name: staging
url: https://staging.infranet.dev
script:
- install_dependencies
- ensure_namespace
- deploy
only:
refs:
- main
except:
- triggers

production:
stage: production
script:
- install_dependencies
- ensure_namespace
- deploy
variables:
KUBE_CONTEXT: ${KUBE_CONTEXT_PROD}
KUBE_NAMESPACE: production
environment:
name: production
url: https://production.infranet.dev
when: manual
only:
refs:
- main
except:
- triggers

production_trigers:
stage: production
variables:
KUBE_CONTEXT_PROD: ${KUBE_CONTEXT_PROD}
KUBE_NAMESPACE: production
host: $CI_PROJECT_PATH_SLUG-$CI_COMMIT_REF_SLUG
name: $CI_ENVIRONMENT_SLUG
environment:
name: production
url: https://production.infranet.dev
script:
- install_dependencies
- ensure_namespace
- deploy
only:
refs:
- triggers

.auto_devops: &auto_devops |
# Auto DevOps variables and functions
[[ "$TRACE" ]] && set -x
export CI_REGISTRY="index.docker.io"
export CI_APPLICATION_REPOSITORY=$CI_REGISTRY/$CI_PROJECT_PATH
export CI_APPLICATION_TAG=$CI_COMMIT_REF_SLUG
export CI_CONTAINER_NAME=ci_job_build_${CI_JOB_ID}
export TILLER_NAMESPACE="kube-system"

function deploy() {

track="${1-stable}"
name="$CI_ENVIRONMENT_SLUG"
echo -e "\nStarting deployment of the project $name..."
tree ./

echo "helm dep build --debug reddit/"
helm dep build --debug reddit/ || true

helm dep ls reddit/

helm template \
--set ui.ingress.host="$host" \
--set ui.image.tag="$(curl -k https://gitlab.infranet.dev/$CI_PROJECT_NAMESPACE/ui/-/raw/main/VERSION)" \
--set post.image.tag="$(curl -k https://gitlab.infranet.dev/$CI_PROJECT_NAMESPACE/post/-/raw/main/VERSION)" \
--set comment.image.tag="$(curl -k https://gitlab.infranet.dev/$CI_PROJECT_NAMESPACE/comment/-/raw/main/VERSION)" \
--set auth.enabled=false \
--namespace="$KUBE_NAMESPACE" --create-namespace \
--version="$CI_PIPELINE_ID-$CI_JOB_ID" \
"$name" \
reddit/

helm upgrade --install --atomic --debug --wait --cleanup-on-fail \
--set ui.ingress.host="$host" \
--set ui.image.tag="$(curl -k https://gitlab.infranet.dev/$CI_PROJECT_NAMESPACE/ui/-/raw/main/VERSION)" \
--set post.image.tag="$(curl -k https://gitlab.infranet.dev/$CI_PROJECT_NAMESPACE/post/-/raw/main/VERSION)" \
--set comment.image.tag="$(curl -k https://gitlab.infranet.dev/$CI_PROJECT_NAMESPACE/comment/-/raw/main/VERSION)" \
--set auth.enabled=false \
--namespace="$KUBE_NAMESPACE" --create-namespace \
--version="$CI_PIPELINE_ID-$CI_JOB_ID" \
"$name" \
reddit/

}

function install_dependencies() {
echo -e "\nInstalling default depecdencies and setting kube context..."
apk add -U openssl curl tar gzip bash ca-certificates git gpg tree
wget -q -O /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub
curl -L -o /usr/bin/kubectl https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
chmod +x /usr/bin/kubectl
kubectl version --client
chmod go-rw ${KUBECONFIG}
kubectl config get-contexts
kubectl config use-context $KUBE_CONTEXT
helm version --client
helm repo add gitlab https://charts.gitlab.io
helm repo add stable https://charts.helm.sh/stable
helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
helm repo update

}

function ensure_namespace() {
kubectl describe namespace "$KUBE_NAMESPACE" || kubectl create namespace "$KUBE_NAMESPACE"
}

function delete() {
track="${1-stable}"
name="$CI_ENVIRONMENT_SLUG"
echo -e "\nDeleting helm project $name..."
helm delete "$name" || true
}

before_script:
- *auto_devops
10 changes: 10 additions & 0 deletions kubernetes/Charts/comment/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
apiVersion: v1
appVersion: 1.0.0
name: comment
version: 1.0.0
description: OTUS reddit application Comment
maintainers:
- name: Someone
email: [email protected]
icon: file://reddit_3983906.png
Binary file added kubernetes/Charts/comment/reddit_3983906.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions kubernetes/Charts/comment/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{{- define "comment.fullname" -}}
{{- printf "%s-%s" .Release.Name .Chart.Name }}
{{- end -}}
35 changes: 35 additions & 0 deletions kubernetes/Charts/comment/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ .Release.Name }}-{{ .Chart.Name }}
namespace: {{ .Values.namespace }}
labels:
app: reddit
component: {{ .Values.labels.component }}
release: {{ .Release.Name }}
spec:
replicas: {{ .Values.replicaCount }}
selector:
matchLabels:
app: reddit
component: {{ .Values.labels.component }}
release: {{ .Release.Name }}
template:
metadata:
name: comment
labels:
app: reddit
component: {{ .Values.labels.component }}
release: {{ .Release.Name }}
spec:
containers:
- name: comment
image: {{ .Values.image.repository }}:{{ .Values.image.tag }}
resources:
limits:
memory: 256Mi
cpu: "1"
env:
- name: COMMENT_DATABASE_HOST
value: {{ .Values.env.databaseHost | default (printf "%s-mongodb" .Release.Name) }}
19 changes: 19 additions & 0 deletions kubernetes/Charts/comment/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
apiVersion: v1
kind: Service
metadata:
name: {{ template "comment.fullname" . }}
namespace: {{ .Values.namespace }}
labels:
app: reddit
component: {{ .Values.labels.component }}
release: {{ .Release.Name }}
spec:
type: ClusterIP
selector:
app: reddit
component: {{ .Values.labels.component }}
ports:
- port: {{ .Values.service.externalPort }}
protocol: TCP
targetPort: {{ .Values.service.internalPort }}
13 changes: 13 additions & 0 deletions kubernetes/Charts/comment/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
service:
internalPort: 9292
externalPort: 9292
image:
repository: 23f03013e37f/comment
tag: latest
namespace: dev
env:
databaseHost:
labels:
component: comment
replicaCount: 1
19 changes: 19 additions & 0 deletions kubernetes/Charts/gitlab-omnibus/.gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
image: registry.gitlab.com/charts/alpine-helm

stages:
- test
- release

lint:
stage: test
script:
- helm lint .
except:
- master

release-chart:
stage: release
script:
- curl --request POST --form "token=$CI_JOB_TOKEN" --form ref=master https://gitlab.com/api/v4/projects/2860651/trigger/pipeline
only:
- master
21 changes: 21 additions & 0 deletions kubernetes/Charts/gitlab-omnibus/.helmignore
Original file line number Diff line number Diff line change
@@ -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
45 changes: 45 additions & 0 deletions kubernetes/Charts/gitlab-omnibus/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "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).
*/}}
{{- define "fullname" -}}
{{- $name := default .Chart.Name .Values.nameOverride -}}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Create a default fully qualified postgresql name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
*/}}
{{- define "postgresql.fullname" -}}
{{- $appName := (include "fullname" .) | trunc 54 | trimSuffix "-" -}}
{{- printf "%s-%s" $appName "postgresql" -}}
{{- end -}}

{{/*
Create a default fully qualified redis name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
*/}}
{{- define "redis.fullname" -}}
{{- $appName := (include "fullname" .) | trunc 57 | trimSuffix "-" -}}
{{- printf "%s-%s" $appName "redis" -}}
{{- end -}}

{{/*
Template for outputing the gitlabUrl
*/}}
{{- define "gitlabUrl" -}}
{{- if .Values.gitlabUrl -}}
{{- .Values.gitlabUrl | quote -}}
{{- else -}}
{{- printf "http://%s-gitlab.%s:8005/" .Release.Name .Release.Namespace | quote -}}
{{- end -}}
{{- end -}}
36 changes: 36 additions & 0 deletions kubernetes/Charts/gitlab-omnibus/templates/gitlab-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ template "fullname" . }}-config
labels:
app: {{ template "fullname" . }}
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
release: "{{ .Release.Name }}"
heritage: "{{ .Release.Service }}"
data:
external_scheme: http
external_hostname: {{ template "fullname" . }}
registry_external_scheme: https
registry_external_hostname: registry.{{ .Values.baseDomain }}
mattermost_external_scheme: https
mattermost_external_hostname: mattermost.{{ .Values.baseDomain }}
mattermost_app_uid: {{ .Values.mattermostAppUID }}
postgres_user: gitlab
postgres_db: gitlab_production
---
apiVersion: v1
kind: Secret
metadata:
name: {{ template "fullname" . }}-secrets
labels:
app: {{ template "fullname" . }}
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
release: "{{ .Release.Name }}"
heritage: "{{ .Release.Service }}"
data:
postgres_password: {{ .Values.postgresPassword }}
initial_shared_runners_registration_token: {{ default "" .Values.initialSharedRunnersRegistrationToken | b64enc | quote }}
mattermost_app_secret: {{ .Values.mattermostAppSecret | b64enc | quote }}
{{- if .Values.gitlabEELicense }}
gitlab_ee_license: {{ .Values.gitlabEELicense | b64enc | quote }}
{{- end }}
Loading
Loading