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

SO1S-200 alb, nlb 연결하기 / External DNS 설정 추가 #8

Merged
merged 12 commits into from
Jul 22, 2022
14 changes: 13 additions & 1 deletion apps/app-backend/dev-values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,16 @@ resources:
cpu: "1000m"
requests:
memory: "1000Mi"
cpu: "1000m"
cpu: "1000m"

ingress:
annotations:
kubernetes.io/ingress.class: alb #alb를 사용한다는 의미
alb.ingress.kubernetes.io/target-type: instance #target이 ec2 인스턴스
alb.ingress.kubernetes.io/scheme: internet-facing #외부에 노출
external-dns.alpha.kubernetes.io/hostname: www.so1s.io
hosts:
- www.so1s.io
paths:
- /
tls: []
60 changes: 52 additions & 8 deletions apps/app-monitoring/dev-values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,58 @@ prometheus:
operator: "Equal"
value: "api"
effect: "NoSchedule"
routePrefix: /prom
routePrefix: /graph
storageSpec:
volumeClaimTemplate:
spec:
accessModes: ["ReadWriteOnce"]
resources:
requests:
storage: 5Gi
service:
type: LoadBalancer
annotations:
service.beta.kubernetes.io/aws-load-balancer-type: "external"
service.beta.kubernetes.io/aws-load-balancer-nlb-target-type: "instance"
service.beta.kubernetes.io/aws-load-balancer-scheme: "internet-facing"
ingress:
ingressClassName: nginx
# ingressClassName: alb
enabled: true
annotations:
kubernetes.io/ingress.class: alb
alb.ingress.kubernetes.io/target-type: instance
alb.ingress.kubernetes.io/scheme: internet-facing
external-dns.alpha.kubernetes.io/hostname: prom.so1s.io
hosts:
- prom.so1s.io
paths:
- /prom
- /
pathType: Prefix
thanosIngress:
enabled: false

alertmanager:
alertmanagerSpec:
tolerations:
- key: kind
operator: "Equal"
value: "api"
effect: "NoSchedule"
# service:
# type: LoadBalancer
# annotations:
# service.beta.kubernetes.io/aws-load-balancer-type: "external"
# service.beta.kubernetes.io/aws-load-balancer-nlb-target-type: "instance"
# service.beta.kubernetes.io/aws-load-balancer-scheme: "internet-facing"
ingress: # 추후에 설정 예정
# ingressClassName: alb
enabled: false
# annotations:
# kubernetes.io/ingress.class: alb
# alb.ingress.kubernetes.io/target-type: instance
# alb.ingress.kubernetes.io/scheme: internet-facing
# external-dns.alpha.kubernetes.io/hostname: dashboard.so1s.io

thanosRuler:
thanosRulerSpec:
tolerations:
Expand Down Expand Up @@ -58,16 +90,28 @@ grafana:
value: "api"
effect: "NoSchedule"
adminPassword: password1234
service:
type: LoadBalancer
annotations:
service.beta.kubernetes.io/aws-load-balancer-type: "external"
service.beta.kubernetes.io/aws-load-balancer-nlb-target-type: "instance"
service.beta.kubernetes.io/aws-load-balancer-scheme: "internet-facing"
ingress:
ingressClassName: nginx
# ingressClassName: alb
enabled: true
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /$2
path: /dashboard(/|$)(.*)
annotations:
kubernetes.io/ingress.class: alb
alb.ingress.kubernetes.io/target-type: instance
alb.ingress.kubernetes.io/scheme: internet-facing
external-dns.alpha.kubernetes.io/hostname: dashboard.so1s.io
# nginx.ingress.kubernetes.io/rewrite-target: /$2
hosts:
- dashboard.so1s.io
path: /
grafana.ini:
server:
domain: so1s.io
root_url: http://so1s.io/dashboard/
root_url: http://dashboard.so1s.io/
serve_from_sub_path: true

## prometheus-node-exporter Configuration
Expand Down
1 change: 1 addition & 0 deletions apps/app-public/dev-values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.
12 changes: 11 additions & 1 deletion charts/backend/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,14 @@ kind: ClusterRole
name: cluster-admin
apiGroup: rbac.authorization.k8s.io
{{- end -}}
{{- end -}}
{{- end -}}

{{- define "backend.serviceAnnotations" -}}
{{- if eq .Values.vender "AWS" -}}
service.beta.kubernetes.io/aws-load-balancer-type: "external"
service.beta.kubernetes.io/aws-load-balancer-nlb-target-type: "instance"
service.beta.kubernetes.io/aws-load-balancer-scheme: "internet-facing"
{{- else if eq .Values.vender "on-premise"}}

{{- end }}
{{- end }}
35 changes: 35 additions & 0 deletions charts/backend/templates/ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{{- if .Values.ingress.enabled -}}
{{- $pathType := .Values.ingress.pathType | default "Prefix" -}}
{{- $serviceName := printf "%s" (include "backend.fullname" .) -}}
{{- $servicePort := .Values.ingress.servicePort | default 80 -}}
{{- $paths := .Values.ingress.paths | default "/" -}}
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
namespace: {{ template "backend.namespace" . }}
name: {{ include "backend.fullname" . }}-ingress
{{- if .Values.ingress.annotations }}
annotations:
{{ toYaml .Values.ingress.annotations | indent 4 }}
{{- end }}
spec:
rules:
{{- if .Values.ingress.hosts }}
{{- range $host := .Values.ingress.hosts }}
- host: {{ tpl $host $ }}
http:
paths:
{{- range $p := $paths }}
- path: {{ tpl $p $ }}
pathType: {{ $pathType }}
backend:
service:
name: {{ $serviceName }}
port:
number: {{ $servicePort }}
{{- end }}
{{- end -}}
{{- end }}
tls:
{{ tpl (toYaml .Values.ingress.tls | indent 4) . }}
{{- end -}}
2 changes: 2 additions & 0 deletions charts/backend/templates/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ apiVersion: v1
kind: Service
metadata:
name: {{ include "backend.fullname" . }}
annotations:
{{- include "backend.serviceAnnotations" . | nindent 4 }}
labels:
{{- include "backend.labels" . | nindent 4 }}
spec:
Expand Down
20 changes: 17 additions & 3 deletions charts/backend/values.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
environment: "develop"

vender: "AWS" # AWS | on-premise

environment: "develop" # develop | production

namespaceOverride: ""

replicaCount: 1

hostname: ""

image:
repository: nginx
tag: ""
Expand All @@ -30,9 +35,18 @@ securityContext: {}
# runAsNonRoot: true
# runAsUser: 1000

ingress:
enabled: true
annotations: {}
labels: {}
hosts: []
paths: []
tls: []
pathType: ""

service:
type: ClusterIP
port: 8080
type: LoadBalancer
port: 80
targetPort: 8080

resources:
Expand Down
13 changes: 13 additions & 0 deletions charts/public/aws-load-balancer-controller/dev-values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# helm install alb -n kube-system -f charts/public/aws-load-balancer-controller/dev-values.yaml eks/aws-load-balancer-controller --create-namespace --wait

clusterName: "So1s"

region: ap-northeast-2

vpcId: vpc-0252f7e64e41bd6d8

tolerations:
- key: kind
operator: "Equal"
value: "public"
effect: "NoSchedule"
File renamed without changes.
24 changes: 24 additions & 0 deletions charts/public/external-dns/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: v2
name: external-dns
description: A Helm chart for Kubernetes

# A chart can be either an 'application' or a 'library' chart.
#
# Application charts are a collection of templates that can be packaged into versioned archives
# to be deployed.
#
# Library charts provide useful utilities or functions for the chart developer. They're included as
# a dependency of application charts to inject those utilities and functions into the rendering
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
type: application

# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.1.0

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "1.16.0"
27 changes: 27 additions & 0 deletions charts/public/external-dns/dev-values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# helm install external-dns -n kube-system -f charts/public/external-dns/dev-values.yaml charts/public/external-dns --create-namespace --wait

serviceAccount:
roleArn: "arn:aws:iam::089143290485:role/external-dns"

image:
repository: k8s.gcr.io/external-dns/external-dns
tag: v0.10.2
pullPolicy: IfNotPresent


tolerations:
- key: kind
operator: "Equal"
value: "public"
effect: "NoSchedule"

deployment:
args:
- --source=service
- --source=ingress
- --domain-filter=so1s.io
- --provider=aws
- --policy=sync
- --aws-zone-type=public # only look at public hosted zones (valid values are public, private or no value for both)
- --registry=txt
- --txt-owner-id=Z061949148T1T03TD2DZ
22 changes: 22 additions & 0 deletions charts/public/external-dns/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
1. Get the application URL by running these commands:
{{- if .Values.ingress.enabled }}
{{- range $host := .Values.ingress.hosts }}
{{- range .paths }}
http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ .path }}
{{- end }}
{{- end }}
{{- else if contains "NodePort" .Values.service.type }}
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "external-dns.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 --namespace {{ .Release.Namespace }} svc -w {{ include "external-dns.fullname" . }}'
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "external-dns.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}")
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.kubernetes.io/name={{ include "external-dns.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}")
echo "Visit http://127.0.0.1:8080 to use your application"
kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT
{{- end }}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "nlb.name" -}}
{{- define "external-dns.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}

Expand All @@ -10,7 +10,7 @@ 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 "nlb.fullname" -}}
{{- define "external-dns.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
Expand All @@ -26,16 +26,16 @@ If release name contains chart name it will be used as a full name.
{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "nlb.chart" -}}
{{- define "external-dns.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "nlb.labels" -}}
helm.sh/chart: {{ include "nlb.chart" . }}
{{ include "nlb.selectorLabels" . }}
{{- define "external-dns.labels" -}}
helm.sh/chart: {{ include "external-dns.chart" . }}
{{ include "external-dns.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
Expand All @@ -45,17 +45,17 @@ app.kubernetes.io/managed-by: {{ .Release.Service }}
{{/*
Selector labels
*/}}
{{- define "nlb.selectorLabels" -}}
app.kubernetes.io/name: {{ include "nlb.name" . }}
{{- define "external-dns.selectorLabels" -}}
app.kubernetes.io/name: {{ include "external-dns.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{/*
Create the name of the service account to use
*/}}
{{- define "nlb.serviceAccountName" -}}
{{- define "external-dns.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "nlb.fullname" .) .Values.serviceAccount.name }}
{{- default (include "external-dns.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
Expand Down
20 changes: 20 additions & 0 deletions charts/public/external-dns/templates/clusterrole.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: {{ include "external-dns.fullname" . }}
rules:
- apiGroups: [""]
resources: ["services"]
verbs: ["get","watch","list"]
- apiGroups: [""]
resources: ["pods"]
verbs: ["get","watch","list"]
- apiGroups: ["networking","networking.k8s.io"]
resources: ["ingresses"]
verbs: ["get","watch","list"]
- apiGroups: [""]
resources: ["nodes"]
verbs: ["get","watch","list"]
- apiGroups: [""]
resources: ["endpoints"]
verbs: ["get","watch","list"]
Loading