Skip to content
This repository was archived by the owner on Jun 14, 2024. It is now read-only.

Commit 1173e35

Browse files
author
Chandra Pratap
authored
Adding Java spring kubernetes sample repo for devops starter (#269)
* initial commit * updated twitter link
1 parent 59e59d6 commit 1173e35

29 files changed

+900
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
FROM mcr.microsoft.com/java/maven:8u192-zulu-debian9 AS build-env
2+
WORKDIR /app
3+
COPY . /app
4+
RUN mvn package
5+
6+
FROM tomcat:8
7+
RUN rm -rf /usr/local/tomcat/webapps/ROOT
8+
COPY --from=build-env /app/target/*.war /usr/local/tomcat/webapps/ROOT.war
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) Microsoft Corporation. All rights reserved.
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
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
| Language | Framework | Platform | Author |
2+
| -------- | -------- |--------|--------|
3+
| Java | Spring | Azure Web App, Virtual Machine| |
4+
5+
6+
# Java Spring boot web application
7+
8+
Sample Java Spring Boot web application that you can use to deploy on Azure.
9+
10+
11+
## License:
12+
13+
See [LICENSE](LICENSE).
14+
15+
## Contributing
16+
17+
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [[email protected]](mailto:[email protected]) with any additional questions or comments.
18+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
apiVersion: v1
2+
description: A Helm chart for Kubernetes
3+
name: sampleapp
4+
version: v0.2.0
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
1. Get the application URL by running these commands:
2+
{{- if .Values.ingress.enabled }}
3+
http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $.Values.ingress.hostname }}{{ $.Values.ingress.path }}
4+
{{- else }}
5+
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
6+
You can watch the status of by running 'kubectl get svc -w {{ template "sampleapp.fullname" . }}'
7+
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ template "sampleapp.fullname" . }} -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
8+
echo http://$SERVICE_IP:{{ .Values.service.port }}
9+
{{- end }}
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 "sampleapp.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 "sampleapp.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 "sampleapp.chart" -}}
31+
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
32+
{{- end -}}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: {{ template "sampleapp.fullname" . }}
5+
labels:
6+
app: {{ template "sampleapp.name" . }}
7+
chart: {{ template "sampleapp.chart" . }}
8+
release: {{ .Release.Name }}
9+
heritage: {{ .Release.Service }}
10+
spec:
11+
replicas: {{ .Values.replicaCount }}
12+
selector:
13+
matchLabels:
14+
app: {{ template "sampleapp.name" . }}
15+
release: {{ .Release.Name }}
16+
template:
17+
metadata:
18+
labels:
19+
app: {{ template "sampleapp.name" . }}
20+
release: {{ .Release.Name }}
21+
spec:
22+
containers:
23+
- name: {{ .Chart.Name }}
24+
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
25+
imagePullPolicy: {{ .Values.image.pullPolicy }}
26+
ports:
27+
- name: http
28+
containerPort: {{ .Values.service.port }}
29+
protocol: TCP
30+
livenessProbe:
31+
httpGet:
32+
path: /
33+
port: http
34+
initialDelaySeconds: 30
35+
readinessProbe:
36+
httpGet:
37+
path: /
38+
port: http
39+
initialDelaySeconds: 30
40+
env:
41+
- name: APPINSIGHTS_INSTRUMENTATIONKEY
42+
value: {{ .Values.applicationInsights.InstrumentationKey }}
43+
{{- $root := . }}
44+
{{- range $ref, $values := .Values.secrets }}
45+
{{- range $key, $value := $values }}
46+
- name: {{ $ref | upper }}_{{ $key | upper }}
47+
valueFrom:
48+
secretKeyRef:
49+
name: {{ template "sampleapp.fullname" $root }}-{{ $ref }}
50+
key: {{ $key }}
51+
{{- end }}
52+
{{- end }}
53+
resources:
54+
{{ toYaml .Values.resources | indent 12 }}
55+
{{- if .Values.imagePullSecrets }}
56+
imagePullSecrets:
57+
{{- range .Values.imagePullSecrets }}
58+
- name: {{ . }}
59+
{{- end}}
60+
{{- end }}
61+
{{- with .Values.nodeSelector }}
62+
nodeSelector:
63+
{{ toYaml . | indent 8 }}
64+
{{- end }}
65+
{{- with .Values.affinity }}
66+
affinity:
67+
{{ toYaml . | indent 8 }}
68+
{{- end }}
69+
{{- with .Values.tolerations }}
70+
tolerations:
71+
{{ toYaml . | indent 8 }}
72+
{{- end }}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{{- if .Values.ingress.enabled -}}
2+
{{- $fullName := include "sampleapp.fullname" . -}}
3+
{{- $serviceName := include "sampleapp.name" . -}}
4+
{{- $servicePort := .Values.service.port -}}
5+
apiVersion: extensions/v1beta1
6+
kind: Ingress
7+
metadata:
8+
name: {{ $fullName }}
9+
labels:
10+
app: {{ $serviceName }}
11+
release: {{ .Release.Name }}
12+
heritage: {{ .Release.Service }}
13+
{{- with .Values.ingress.annotations }}
14+
annotations:
15+
{{ toYaml . | indent 4 }}
16+
{{- end }}
17+
spec:
18+
{{- if .Values.ingress.tls }}
19+
tls:
20+
{{- range .Values.ingress.tls }}
21+
- hosts:
22+
{{- range .hosts }}
23+
- {{ . }}
24+
{{- end }}
25+
secretName: {{ .secretName }}
26+
{{- end }}
27+
{{- end }}
28+
rules:
29+
- host: {{ .Values.ingress.hostname | quote }}
30+
http:
31+
paths:
32+
- path: /
33+
backend:
34+
serviceName: {{ $serviceName }}
35+
servicePort: {{ $servicePort }}
36+
{{- end }}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{{- $root := . }}
2+
{{- range $name, $values := .Values.secrets }}
3+
apiVersion: v1
4+
kind: Secret
5+
metadata:
6+
name: {{ template "sampleapp.fullname" $root }}-{{ $name }}
7+
data:
8+
{{- range $key, $value := $values }}
9+
{{ $key }}: {{ $value | b64enc }}
10+
{{- end }}
11+
---
12+
{{- end }}

0 commit comments

Comments
 (0)