diff --git a/chart/Chart.yaml b/chart/Chart.yaml new file mode 100644 index 0000000..21d793f --- /dev/null +++ b/chart/Chart.yaml @@ -0,0 +1,13 @@ +name: testapp +version: 1.0.0 +appVersion: 1.0.0 +description: Kubernetes Test Application +keywords: +- go +- k8s +- test +sources: +- https://git.giftfish.de/ston1th/test +maintainers: +- name: ston1th + email: ston1th@giftfish.de diff --git a/chart/templates/deploymant-db.yaml b/chart/templates/deploymant-db.yaml new file mode 100644 index 0000000..dd3b4b3 --- /dev/null +++ b/chart/templates/deploymant-db.yaml @@ -0,0 +1,71 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ template "testapp.fullname" . }}-db + labels: + app: {{ template "testapp.name" . }}-db + chart: "{{ .Chart.Name }}-{{ .Chart.Version }}" + release: "{{ .Release.Name }}" + heritage: "{{ .Release.Service }}" + component: db +spec: + replicas: {{ .Values.db.replicas }} + template: + metadata: + annotations: +{{- if .Values.db.annotations }} +{{ toYaml .Values.db.annotations | indent 8 }} +{{- end }} + labels: + app: {{ template "testapp.name" . }}-db + release: "{{ .Release.Name }}" + component: db + spec: +{{- if .Values.db.schedulerName }} + schedulerName: "{{ .Values.db.schedulerName }}" +{{- end }} +{{- if .Values.db.affinity }} + affinity: +{{ toYaml .Values.db.affinity | indent 8 }} +{{- end }} +{{- if .Values.db.nodeSelector }} + nodeSelector: +{{ toYaml .Values.db.nodeSelector | indent 8 }} +{{- end }} + containers: + - name: {{ template "testapp.fullname" . }}-db + image: "{{ .Values.images.db.repository }}:{{ .Values.images.db.tag }}" + imagePullPolicy: {{ .Values.images.db.pullPolicy }} + ports: + - name: http + containerPort: 8080 + protocol: TCP + env: + {{- range $key, $value := .Values.db.env }} + - name: {{ $key }} + value: {{ $value | quote }} + {{- end }} + resources: +{{ toYaml .Values.db.resources | indent 10 }} +{{- if .Values.db.livenessProbe.enabled }} + livenessProbe: + httpGet: + path: "/healthz" + port: http + initialDelaySeconds: {{ .Values.db.livenessProbe.initialDelaySeconds }} + periodSeconds: {{ .Values.db.livenessProbe.periodSeconds }} + timeoutSeconds: {{ .Values.db.livenessProbe.timeoutSeconds }} + successThreshold: {{ .Values.db.livenessProbe.successThreshold }} + failureThreshold: {{ .Values.db.livenessProbe.failureThreshold }} +{{- end }} +{{- if .Values.db.readinessProbe.enabled }} + readinessProbe: + httpGet: + path: "/healthz" + port: http + initialDelaySeconds: {{ .Values.db.readinessProbe.initialDelaySeconds }} + periodSeconds: {{ .Values.db.readinessProbe.periodSeconds }} + timeoutSeconds: {{ .Values.db.readinessProbe.timeoutSeconds }} + successThreshold: {{ .Values.db.readinessProbe.successThreshold }} + failureThreshold: {{ .Values.db.readinessProbe.failureThreshold }} +{{- end }} diff --git a/chart/templates/deploymant-srv.yaml b/chart/templates/deploymant-srv.yaml new file mode 100644 index 0000000..fd44fc2 --- /dev/null +++ b/chart/templates/deploymant-srv.yaml @@ -0,0 +1,73 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ template "testapp.fullname" . }}-srv + labels: + app: {{ template "testapp.name" . }}-srv + chart: "{{ .Chart.Name }}-{{ .Chart.Version }}" + release: "{{ .Release.Name }}" + heritage: "{{ .Release.Service }}" + component: srv +spec: + replicas: {{ .Values.srv.replicas }} + template: + metadata: + annotations: +{{- if .Values.srv.annotations }} +{{ toYaml .Values.srv.annotations | indent 8 }} +{{- end }} + labels: + app: {{ template "testapp.name" . }}-srv + release: "{{ .Release.Name }}" + component: srv + spec: +{{- if .Values.srv.schedulerName }} + schedulerName: "{{ .Values.srv.schedulerName }}" +{{- end }} +{{- if .Values.srv.affinity }} + affinity: +{{ toYaml .Values.srv.affinity | indent 8 }} +{{- end }} +{{- if .Values.srv.nodeSelector }} + nodeSelector: +{{ toYaml .Values.srv.nodeSelector | indent 8 }} +{{- end }} + containers: + - name: {{ template "testapp.fullname" . }}-srv + image: "{{ .Values.images.srv.repository }}:{{ .Values.images.srv.tag }}" + imagePullPolicy: {{ .Values.images.srv.pullPolicy }} + ports: + - name: http + containerPort: 8080 + protocol: TCP + env: + - name: DB_HOST + value: {{ template "testapp.fullname" . }}-db.{{ Release.Namespace }}.svc + {{- range $key, $value := .Values.srv.env }} + - name: {{ $key }} + value: {{ $value | quote }} + {{- end }} + resources: +{{ toYaml .Values.srv.resources | indent 10 }} +{{- if .Values.srv.livenessProbe.enabled }} + livenessProbe: + httpGet: + path: "/healthz" + port: http + initialDelaySeconds: {{ .Values.srv.livenessProbe.initialDelaySeconds }} + periodSeconds: {{ .Values.srv.livenessProbe.periodSeconds }} + timeoutSeconds: {{ .Values.srv.livenessProbe.timeoutSeconds }} + successThreshold: {{ .Values.srv.livenessProbe.successThreshold }} + failureThreshold: {{ .Values.srv.livenessProbe.failureThreshold }} +{{- end }} +{{- if .Values.srv.readinessProbe.enabled }} + readinessProbe: + httpGet: + path: "/healthz" + port: http + initialDelaySeconds: {{ .Values.srv.readinessProbe.initialDelaySeconds }} + periodSeconds: {{ .Values.srv.readinessProbe.periodSeconds }} + timeoutSeconds: {{ .Values.srv.readinessProbe.timeoutSeconds }} + successThreshold: {{ .Values.srv.readinessProbe.successThreshold }} + failureThreshold: {{ .Values.srv.readinessProbe.failureThreshold }} +{{- end }} diff --git a/chart/templates/service-db.yaml b/chart/templates/service-db.yaml new file mode 100644 index 0000000..1b6188b --- /dev/null +++ b/chart/templates/service-db.yaml @@ -0,0 +1,25 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ template "drone.fullname" . }}-db + annotations: + {{- range $key, $value := .Values.Db.service.annotations }} + {{ $key }}: {{ $value | quote }} + {{- end }} + labels: + app: {{ template "drone.name" . }}-db + chart: "{{ .Chart.Name }}-{{ .Chart.Version }}" + release: "{{ .Release.Name }}" + heritage: "{{ .Release.Service }}" +spec: + type: {{ .Values.Db.service.type }} + ports: + - name: http + port: {{ .Values.Db.service.httpPort }} + targetPort: 8080 +{{- if hasKey .Values.Db.service "nodePort" }} + nodePort: {{ .Values.Db.service.nodePort }} +{{- end }} + selector: + app: {{ template "drone.name" . }}-db + release: {{ .Release.Name | quote }} diff --git a/chart/templates/service-srv.yaml b/chart/templates/service-srv.yaml new file mode 100644 index 0000000..57e6542 --- /dev/null +++ b/chart/templates/service-srv.yaml @@ -0,0 +1,34 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ template "testapp.fullname" . }}-srv + annotations: + getambassador.io/config: | + --- + apiVersion: ambassador/v0 + kind: Mapping + name: {{ template "testapp.fullname" . }}-srv_mapping + host: "^{{ .Values.srv.host }}.*$" + host_regex: true + prefix: / + service: {{ template "testapp.fullname" . }}-srv.{{ Release.Namespace }}.svc:8080 + {{- range $key, $value := .Values.service.srv.annotations }} + {{ $key }}: {{ $value | quote }} + {{- end }} + labels: + app: {{ template "testapp.name" . }}-srv + chart: "{{ .Chart.Name }}-{{ .Chart.Version }}" + release: "{{ .Release.Name }}" + heritage: "{{ .Release.Service }}" +spec: + type: {{ .Values.service.srv.type }} + ports: + - name: http + port: {{ .Values.service.srv.httpPort }} + targetPort: 8080 +{{- if hasKey .Values.service.srv "nodePort" }} + nodePort: {{ .Values.service.srv.nodePort }} +{{- end }} + selector: + app: {{ template "testapp.name" . }}-srv + release: {{ .Release.Name | quote }} diff --git a/chart/values.yaml b/chart/values.yaml new file mode 100644 index 0000000..49f5655 --- /dev/null +++ b/chart/values.yaml @@ -0,0 +1,80 @@ +appVersion: "1.0.0" + +images: + srv: + repository: "127.0.0.1:5000/testapp/srv" + tag: 1.0.0 + pullPolicy: IfNotPresent + db: + repository: "127.0.0.1:5000/testapp/db" + tag: 1.0.0 + pullPolicy: IfNotPresent + +service: + srv: + httpPort: 80 + # nodePort: 32015 + type: ClusterIP + # annotations: + db: + httpPort: 80 + # nodePort: 32015 + type: ClusterIP + # annotations: + +srv: + # host: "srv.kube" + # env: + annotations: {} + resources: {} + # requests: + # memory: 32Mi + # cpu: 40m + # limits: + # memory: 2Gi + # cpu: 1 + livenessProbe: + enabled: true + failureThreshold: 3 + initialDelaySeconds: 0 + periodSeconds: 10 + successThreshold: 1 + timeoutSeconds: 1 + readinessProbe: + enabled: true + failureThreshold: 3 + initialDelaySeconds: 0 + periodSeconds: 10 + successThreshold: 1 + timeoutSeconds: 1 + # schedulerName: + affinity: {} + nodeSelector: {} + +db: + # env: + annotations: {} + resources: {} + # requests: + # memory: 32Mi + # cpu: 40m + # limits: + # memory: 2Gi + # cpu: 1 + livenessProbe: + enabled: true + failureThreshold: 3 + initialDelaySeconds: 0 + periodSeconds: 10 + successThreshold: 1 + timeoutSeconds: 1 + readinessProbe: + enabled: true + failureThreshold: 3 + initialDelaySeconds: 0 + periodSeconds: 10 + successThreshold: 1 + timeoutSeconds: 1 + # schedulerName: + affinity: {} + nodeSelector: {} diff --git a/srv.go b/srv.go index c51d44b..eb83467 100644 --- a/srv.go +++ b/srv.go @@ -27,9 +27,7 @@ func main() { http.Error(w, err.Error(), http.StatusInternalServerError) return } - //url := "http://" + os.Getenv("DB_SERVICE_HOST") + ":" + os.Getenv("DB_SERVICE_PORT") - //url := "http://testapp-db.default.svc.cluster.local:8080" - url := "http://testapp-db:8080" + url := "http://" + os.Getenv("DB_HOST") c := &http.Client{Transport: &http.Transport{ DialContext: (&net.Dialer{ Timeout: 5 * time.Second,