├── .gitignore
├── Devoxx-2017-Spring_Boot-Kubernetes.pdf
├── LICENSE
├── README.md
├── actors
├── .gitignore
├── .mvn
│ └── wrapper
│ │ ├── maven-wrapper.jar
│ │ └── maven-wrapper.properties
├── Dockerfile
├── config
│ ├── actors-config.yaml
│ ├── actors-deployment.yaml
│ └── actors-svc.yaml
├── mvnw
├── mvnw.cmd
├── pom.xml
└── src
│ ├── main
│ ├── docker
│ │ └── assembly.xml
│ ├── java
│ │ └── com
│ │ │ └── springdeveloper
│ │ │ └── k8s
│ │ │ └── actors
│ │ │ ├── Actor.java
│ │ │ ├── ActorRepository.java
│ │ │ └── ActorsApplication.java
│ └── resources
│ │ ├── application-default.properties
│ │ └── application-kubernetes.properties
│ └── test
│ └── java
│ └── com
│ └── springdeveloper
│ └── k8s
│ └── actors
│ └── ActorsApplicationTests.java
├── demo-actors.adoc
├── demo-hello.adoc
├── demo-microservices.adoc
├── hello
├── .gitignore
├── .mvn
│ └── wrapper
│ │ ├── maven-wrapper.jar
│ │ └── maven-wrapper.properties
├── Dockerfile
├── hello-deployment.yaml
├── hello-svc.yaml
├── mvnw
├── mvnw.cmd
├── pom.xml
└── src
│ ├── main
│ ├── java
│ │ └── com
│ │ │ └── springdeveloper
│ │ │ └── k8s
│ │ │ └── hello
│ │ │ └── HelloApplication.java
│ └── resources
│ │ └── application.properties
│ └── test
│ └── java
│ └── com
│ └── springdeveloper
│ └── k8s
│ └── hello
│ └── HelloApplicationTests.java
└── mysql
├── mysql-deployment.yaml
├── mysql-pvc.yaml
├── mysql-secrets.yaml
└── mysql-svc.yaml
/.gitignore:
--------------------------------------------------------------------------------
1 | *.DS_Store
2 |
--------------------------------------------------------------------------------
/Devoxx-2017-Spring_Boot-Kubernetes.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/trisberg/devoxx-spring-boot-k8s/02dd60d3d9005bc956fe3c794f89eddcf0ce975f/Devoxx-2017-Spring_Boot-Kubernetes.pdf
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright {yyyy} {name of copyright owner}
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # devoxx-spring-boot-k8s
2 | Demos and slides for Spring Boot on Kubernetes talk
3 |
--------------------------------------------------------------------------------
/actors/.gitignore:
--------------------------------------------------------------------------------
1 | target/
2 | !.mvn/wrapper/maven-wrapper.jar
3 |
4 | ### STS ###
5 | .apt_generated
6 | .classpath
7 | .factorypath
8 | .project
9 | .settings
10 | .springBeans
11 |
12 | ### IntelliJ IDEA ###
13 | .idea
14 | *.iws
15 | *.iml
16 | *.ipr
17 |
18 | ### NetBeans ###
19 | nbproject/private/
20 | build/
21 | nbbuild/
22 | dist/
23 | nbdist/
24 | .nb-gradle/
25 |
26 | ### Visual Code
27 | .vscode
28 |
--------------------------------------------------------------------------------
/actors/.mvn/wrapper/maven-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/trisberg/devoxx-spring-boot-k8s/02dd60d3d9005bc956fe3c794f89eddcf0ce975f/actors/.mvn/wrapper/maven-wrapper.jar
--------------------------------------------------------------------------------
/actors/.mvn/wrapper/maven-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.0/apache-maven-3.5.0-bin.zip
2 |
--------------------------------------------------------------------------------
/actors/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM java:8-alpine
2 | VOLUME /tmp
3 | ARG JAR_FILE
4 | ADD ./target/${JAR_FILE} /actors.jar
5 | RUN sh -c 'touch /actors.jar'
6 | ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/actors.jar"]
--------------------------------------------------------------------------------
/actors/config/actors-config.yaml:
--------------------------------------------------------------------------------
1 | apiVersion: v1
2 | kind: ConfigMap
3 | metadata:
4 | name: actors
5 | labels:
6 | app: actors
7 | data:
8 | application.yaml: |-
9 | security:
10 | basic:
11 | enabled: false
12 | spring:
13 | datasource:
14 | url: jdbc:mysql://${MYSQL_SERVICE_HOST}:${MYSQL_SERVICE_PORT}/mysql
15 | username: root
16 | password: ${MYSQL_ROOT_PASSWORD}
17 | driverClassName: com.mysql.jdbc.Driver
18 | testOnBorrow: true
19 | validationQuery: "SELECT 1"
20 |
--------------------------------------------------------------------------------
/actors/config/actors-deployment.yaml:
--------------------------------------------------------------------------------
1 | apiVersion: extensions/v1beta1
2 | kind: Deployment
3 | metadata:
4 | name: actors
5 | labels:
6 | app: actors
7 | spec:
8 | replicas: 1
9 | template:
10 | metadata:
11 | labels:
12 | app: actors
13 | spec:
14 | containers:
15 | - name: actors
16 | image: trisberg/actors:0.0.1-SNAPSHOT
17 | imagePullPolicy: IfNotPresent
18 | ports:
19 | - containerPort: 80
20 | resources:
21 | limits:
22 | cpu: 1.0
23 | memory: 1024Mi
24 | requests:
25 | cpu: 0.5
26 | memory: 640Mi
27 | livenessProbe:
28 | httpGet:
29 | path: /application/status
30 | port: 80
31 | initialDelaySeconds: 90
32 | periodSeconds: 15
33 | timeoutSeconds: 5
34 | readinessProbe:
35 | httpGet:
36 | path: /application/status
37 | port: 80
38 | initialDelaySeconds: 45
39 | periodSeconds: 15
40 | timeoutSeconds: 5
41 | env:
42 | - name: SERVER_PORT
43 | value: '80'
44 | - name: SPRING_PROFILES_ACTIVE
45 | value: kubernetes
46 | - name: MYSQL_ROOT_PASSWORD
47 | valueFrom:
48 | secretKeyRef:
49 | name: mysql
50 | key: mysql-root-password
51 | volumeMounts:
52 | - name: application-config
53 | mountPath: "/config"
54 | readOnly: true
55 | volumes:
56 | - name: application-config
57 | configMap:
58 | name: actors
59 | items:
60 | - key: application.yaml
61 | path: application-kubernetes.yaml
62 |
--------------------------------------------------------------------------------
/actors/config/actors-svc.yaml:
--------------------------------------------------------------------------------
1 | kind: Service
2 | apiVersion: v1
3 | metadata:
4 | name: actors
5 | labels:
6 | app: actors
7 | spec:
8 | # If you are running k8s on a local dev box or using minikube, you can use type NodePort instead of LoadBalancer
9 | type: NodePort
10 | ports:
11 | - port: 80
12 | selector:
13 | app: actors
14 |
--------------------------------------------------------------------------------
/actors/mvnw:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | # ----------------------------------------------------------------------------
3 | # Licensed to the Apache Software Foundation (ASF) under one
4 | # or more contributor license agreements. See the NOTICE file
5 | # distributed with this work for additional information
6 | # regarding copyright ownership. The ASF licenses this file
7 | # to you under the Apache License, Version 2.0 (the
8 | # "License"); you may not use this file except in compliance
9 | # with the License. You may obtain a copy of the License at
10 | #
11 | # http://www.apache.org/licenses/LICENSE-2.0
12 | #
13 | # Unless required by applicable law or agreed to in writing,
14 | # software distributed under the License is distributed on an
15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 | # KIND, either express or implied. See the License for the
17 | # specific language governing permissions and limitations
18 | # under the License.
19 | # ----------------------------------------------------------------------------
20 |
21 | # ----------------------------------------------------------------------------
22 | # Maven2 Start Up Batch script
23 | #
24 | # Required ENV vars:
25 | # ------------------
26 | # JAVA_HOME - location of a JDK home dir
27 | #
28 | # Optional ENV vars
29 | # -----------------
30 | # M2_HOME - location of maven2's installed home dir
31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven
32 | # e.g. to debug Maven itself, use
33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files
35 | # ----------------------------------------------------------------------------
36 |
37 | if [ -z "$MAVEN_SKIP_RC" ] ; then
38 |
39 | if [ -f /etc/mavenrc ] ; then
40 | . /etc/mavenrc
41 | fi
42 |
43 | if [ -f "$HOME/.mavenrc" ] ; then
44 | . "$HOME/.mavenrc"
45 | fi
46 |
47 | fi
48 |
49 | # OS specific support. $var _must_ be set to either true or false.
50 | cygwin=false;
51 | darwin=false;
52 | mingw=false
53 | case "`uname`" in
54 | CYGWIN*) cygwin=true ;;
55 | MINGW*) mingw=true;;
56 | Darwin*) darwin=true
57 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home
58 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html
59 | if [ -z "$JAVA_HOME" ]; then
60 | if [ -x "/usr/libexec/java_home" ]; then
61 | export JAVA_HOME="`/usr/libexec/java_home`"
62 | else
63 | export JAVA_HOME="/Library/Java/Home"
64 | fi
65 | fi
66 | ;;
67 | esac
68 |
69 | if [ -z "$JAVA_HOME" ] ; then
70 | if [ -r /etc/gentoo-release ] ; then
71 | JAVA_HOME=`java-config --jre-home`
72 | fi
73 | fi
74 |
75 | if [ -z "$M2_HOME" ] ; then
76 | ## resolve links - $0 may be a link to maven's home
77 | PRG="$0"
78 |
79 | # need this for relative symlinks
80 | while [ -h "$PRG" ] ; do
81 | ls=`ls -ld "$PRG"`
82 | link=`expr "$ls" : '.*-> \(.*\)$'`
83 | if expr "$link" : '/.*' > /dev/null; then
84 | PRG="$link"
85 | else
86 | PRG="`dirname "$PRG"`/$link"
87 | fi
88 | done
89 |
90 | saveddir=`pwd`
91 |
92 | M2_HOME=`dirname "$PRG"`/..
93 |
94 | # make it fully qualified
95 | M2_HOME=`cd "$M2_HOME" && pwd`
96 |
97 | cd "$saveddir"
98 | # echo Using m2 at $M2_HOME
99 | fi
100 |
101 | # For Cygwin, ensure paths are in UNIX format before anything is touched
102 | if $cygwin ; then
103 | [ -n "$M2_HOME" ] &&
104 | M2_HOME=`cygpath --unix "$M2_HOME"`
105 | [ -n "$JAVA_HOME" ] &&
106 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
107 | [ -n "$CLASSPATH" ] &&
108 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
109 | fi
110 |
111 | # For Migwn, ensure paths are in UNIX format before anything is touched
112 | if $mingw ; then
113 | [ -n "$M2_HOME" ] &&
114 | M2_HOME="`(cd "$M2_HOME"; pwd)`"
115 | [ -n "$JAVA_HOME" ] &&
116 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`"
117 | # TODO classpath?
118 | fi
119 |
120 | if [ -z "$JAVA_HOME" ]; then
121 | javaExecutable="`which javac`"
122 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then
123 | # readlink(1) is not available as standard on Solaris 10.
124 | readLink=`which readlink`
125 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then
126 | if $darwin ; then
127 | javaHome="`dirname \"$javaExecutable\"`"
128 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac"
129 | else
130 | javaExecutable="`readlink -f \"$javaExecutable\"`"
131 | fi
132 | javaHome="`dirname \"$javaExecutable\"`"
133 | javaHome=`expr "$javaHome" : '\(.*\)/bin'`
134 | JAVA_HOME="$javaHome"
135 | export JAVA_HOME
136 | fi
137 | fi
138 | fi
139 |
140 | if [ -z "$JAVACMD" ] ; then
141 | if [ -n "$JAVA_HOME" ] ; then
142 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
143 | # IBM's JDK on AIX uses strange locations for the executables
144 | JAVACMD="$JAVA_HOME/jre/sh/java"
145 | else
146 | JAVACMD="$JAVA_HOME/bin/java"
147 | fi
148 | else
149 | JAVACMD="`which java`"
150 | fi
151 | fi
152 |
153 | if [ ! -x "$JAVACMD" ] ; then
154 | echo "Error: JAVA_HOME is not defined correctly." >&2
155 | echo " We cannot execute $JAVACMD" >&2
156 | exit 1
157 | fi
158 |
159 | if [ -z "$JAVA_HOME" ] ; then
160 | echo "Warning: JAVA_HOME environment variable is not set."
161 | fi
162 |
163 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
164 |
165 | # traverses directory structure from process work directory to filesystem root
166 | # first directory with .mvn subdirectory is considered project base directory
167 | find_maven_basedir() {
168 |
169 | if [ -z "$1" ]
170 | then
171 | echo "Path not specified to find_maven_basedir"
172 | return 1
173 | fi
174 |
175 | basedir="$1"
176 | wdir="$1"
177 | while [ "$wdir" != '/' ] ; do
178 | if [ -d "$wdir"/.mvn ] ; then
179 | basedir=$wdir
180 | break
181 | fi
182 | # workaround for JBEAP-8937 (on Solaris 10/Sparc)
183 | if [ -d "${wdir}" ]; then
184 | wdir=`cd "$wdir/.."; pwd`
185 | fi
186 | # end of workaround
187 | done
188 | echo "${basedir}"
189 | }
190 |
191 | # concatenates all lines of a file
192 | concat_lines() {
193 | if [ -f "$1" ]; then
194 | echo "$(tr -s '\n' ' ' < "$1")"
195 | fi
196 | }
197 |
198 | BASE_DIR=`find_maven_basedir "$(pwd)"`
199 | if [ -z "$BASE_DIR" ]; then
200 | exit 1;
201 | fi
202 |
203 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}
204 | echo $MAVEN_PROJECTBASEDIR
205 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
206 |
207 | # For Cygwin, switch paths to Windows format before running java
208 | if $cygwin; then
209 | [ -n "$M2_HOME" ] &&
210 | M2_HOME=`cygpath --path --windows "$M2_HOME"`
211 | [ -n "$JAVA_HOME" ] &&
212 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
213 | [ -n "$CLASSPATH" ] &&
214 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
215 | [ -n "$MAVEN_PROJECTBASEDIR" ] &&
216 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"`
217 | fi
218 |
219 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
220 |
221 | exec "$JAVACMD" \
222 | $MAVEN_OPTS \
223 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
224 | "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
225 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@"
226 |
--------------------------------------------------------------------------------
/actors/mvnw.cmd:
--------------------------------------------------------------------------------
1 | @REM ----------------------------------------------------------------------------
2 | @REM Licensed to the Apache Software Foundation (ASF) under one
3 | @REM or more contributor license agreements. See the NOTICE file
4 | @REM distributed with this work for additional information
5 | @REM regarding copyright ownership. The ASF licenses this file
6 | @REM to you under the Apache License, Version 2.0 (the
7 | @REM "License"); you may not use this file except in compliance
8 | @REM with the License. You may obtain a copy of the License at
9 | @REM
10 | @REM http://www.apache.org/licenses/LICENSE-2.0
11 | @REM
12 | @REM Unless required by applicable law or agreed to in writing,
13 | @REM software distributed under the License is distributed on an
14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | @REM KIND, either express or implied. See the License for the
16 | @REM specific language governing permissions and limitations
17 | @REM under the License.
18 | @REM ----------------------------------------------------------------------------
19 |
20 | @REM ----------------------------------------------------------------------------
21 | @REM Maven2 Start Up Batch script
22 | @REM
23 | @REM Required ENV vars:
24 | @REM JAVA_HOME - location of a JDK home dir
25 | @REM
26 | @REM Optional ENV vars
27 | @REM M2_HOME - location of maven2's installed home dir
28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands
29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending
30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven
31 | @REM e.g. to debug Maven itself, use
32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files
34 | @REM ----------------------------------------------------------------------------
35 |
36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on'
37 | @echo off
38 | @REM enable echoing my setting MAVEN_BATCH_ECHO to 'on'
39 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO%
40 |
41 | @REM set %HOME% to equivalent of $HOME
42 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%")
43 |
44 | @REM Execute a user defined script before this one
45 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre
46 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending
47 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat"
48 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd"
49 | :skipRcPre
50 |
51 | @setlocal
52 |
53 | set ERROR_CODE=0
54 |
55 | @REM To isolate internal variables from possible post scripts, we use another setlocal
56 | @setlocal
57 |
58 | @REM ==== START VALIDATION ====
59 | if not "%JAVA_HOME%" == "" goto OkJHome
60 |
61 | echo.
62 | echo Error: JAVA_HOME not found in your environment. >&2
63 | echo Please set the JAVA_HOME variable in your environment to match the >&2
64 | echo location of your Java installation. >&2
65 | echo.
66 | goto error
67 |
68 | :OkJHome
69 | if exist "%JAVA_HOME%\bin\java.exe" goto init
70 |
71 | echo.
72 | echo Error: JAVA_HOME is set to an invalid directory. >&2
73 | echo JAVA_HOME = "%JAVA_HOME%" >&2
74 | echo Please set the JAVA_HOME variable in your environment to match the >&2
75 | echo location of your Java installation. >&2
76 | echo.
77 | goto error
78 |
79 | @REM ==== END VALIDATION ====
80 |
81 | :init
82 |
83 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn".
84 | @REM Fallback to current working directory if not found.
85 |
86 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR%
87 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir
88 |
89 | set EXEC_DIR=%CD%
90 | set WDIR=%EXEC_DIR%
91 | :findBaseDir
92 | IF EXIST "%WDIR%"\.mvn goto baseDirFound
93 | cd ..
94 | IF "%WDIR%"=="%CD%" goto baseDirNotFound
95 | set WDIR=%CD%
96 | goto findBaseDir
97 |
98 | :baseDirFound
99 | set MAVEN_PROJECTBASEDIR=%WDIR%
100 | cd "%EXEC_DIR%"
101 | goto endDetectBaseDir
102 |
103 | :baseDirNotFound
104 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR%
105 | cd "%EXEC_DIR%"
106 |
107 | :endDetectBaseDir
108 |
109 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig
110 |
111 | @setlocal EnableExtensions EnableDelayedExpansion
112 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a
113 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS%
114 |
115 | :endReadAdditionalConfig
116 |
117 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe"
118 |
119 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar"
120 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
121 |
122 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %*
123 | if ERRORLEVEL 1 goto error
124 | goto end
125 |
126 | :error
127 | set ERROR_CODE=1
128 |
129 | :end
130 | @endlocal & set ERROR_CODE=%ERROR_CODE%
131 |
132 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost
133 | @REM check for post script, once with legacy .bat ending and once with .cmd ending
134 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat"
135 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd"
136 | :skipRcPost
137 |
138 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on'
139 | if "%MAVEN_BATCH_PAUSE%" == "on" pause
140 |
141 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE%
142 |
143 | exit /B %ERROR_CODE%
144 |
--------------------------------------------------------------------------------
/actors/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | com.springdeveloper.k8s
7 | actors
8 | 0.0.1-SNAPSHOT
9 | jar
10 |
11 | actors
12 | Demo project for Spring Boot
13 |
14 |
15 | org.springframework.boot
16 | spring-boot-starter-parent
17 | 2.0.0.M5
18 |
19 |
20 |
21 |
22 | UTF-8
23 | UTF-8
24 | 1.8
25 |
26 |
27 |
28 |
29 | org.springframework.boot
30 | spring-boot-starter-actuator
31 |
32 |
33 | org.springframework.boot
34 | spring-boot-starter-data-jpa
35 |
36 |
37 | org.springframework.boot
38 | spring-boot-starter-data-rest
39 |
40 |
41 | org.springframework.boot
42 | spring-boot-starter-web
43 |
44 |
45 |
46 | org.hibernate
47 | hibernate-core
48 | 4.3.10.Final
49 |
50 |
51 | org.hibernate
52 | hibernate-entitymanager
53 | 4.3.10.Final
54 |
55 |
56 |
57 | org.hsqldb
58 | hsqldb
59 | runtime
60 |
61 |
62 | mysql
63 | mysql-connector-java
64 | runtime
65 |
66 |
67 | org.springframework.boot
68 | spring-boot-starter-test
69 | test
70 |
71 |
72 |
73 |
74 |
75 |
76 | org.springframework.boot
77 | spring-boot-maven-plugin
78 |
79 |
80 | com.spotify
81 | dockerfile-maven-plugin
82 | 1.3.6
83 |
84 | ${user.name}/${project.artifactId}
85 | ${project.version}
86 |
87 | ${project.build.finalName}.jar
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 | spring-snapshots
97 | Spring Snapshots
98 | https://repo.spring.io/snapshot
99 |
100 | true
101 |
102 |
103 |
104 | spring-milestones
105 | Spring Milestones
106 | https://repo.spring.io/milestone
107 |
108 | false
109 |
110 |
111 |
112 |
113 |
114 |
115 | spring-snapshots
116 | Spring Snapshots
117 | https://repo.spring.io/snapshot
118 |
119 | true
120 |
121 |
122 |
123 | spring-milestones
124 | Spring Milestones
125 | https://repo.spring.io/milestone
126 |
127 | false
128 |
129 |
130 |
131 |
132 |
133 |
134 |
--------------------------------------------------------------------------------
/actors/src/main/docker/assembly.xml:
--------------------------------------------------------------------------------
1 |
6 | actors
7 |
8 |
9 |
10 | com.springdeveloper.k8s:actors
11 |
12 | .
13 | actors.jar
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/actors/src/main/java/com/springdeveloper/k8s/actors/Actor.java:
--------------------------------------------------------------------------------
1 | package com.springdeveloper.k8s.actors;
2 |
3 | import javax.persistence.Entity;
4 | import javax.persistence.GeneratedValue;
5 | import javax.persistence.Id;
6 |
7 | @Entity
8 | public class Actor {
9 |
10 | @Id
11 | @GeneratedValue
12 | Long id;
13 |
14 | String name;
15 |
16 | int age;
17 |
18 | public Long getId() {
19 | return id;
20 | }
21 |
22 | public String getName() {
23 | return name;
24 | }
25 |
26 | public void setName(String name) {
27 | this.name = name;
28 | }
29 |
30 | public int getAge() {
31 | return age;
32 | }
33 |
34 | public void setAge(int age) {
35 | this.age = age;
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/actors/src/main/java/com/springdeveloper/k8s/actors/ActorRepository.java:
--------------------------------------------------------------------------------
1 | package com.springdeveloper.k8s.actors;
2 |
3 | import java.util.List;
4 |
5 | import org.springframework.data.repository.PagingAndSortingRepository;
6 | import org.springframework.data.repository.query.Param;
7 |
8 | public interface ActorRepository extends PagingAndSortingRepository {
9 |
10 | List findByName(@Param("name") String name);
11 |
12 | }
13 |
--------------------------------------------------------------------------------
/actors/src/main/java/com/springdeveloper/k8s/actors/ActorsApplication.java:
--------------------------------------------------------------------------------
1 | package com.springdeveloper.k8s.actors;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class ActorsApplication {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(ActorsApplication.class, args);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/actors/src/main/resources/application-default.properties:
--------------------------------------------------------------------------------
1 | endpoints.env.enabled=true
2 | spring.datasource.url=jdbc:hsqldb:file:target/testdb
3 | spring.datasource.username=sa
4 | spring.jpa.hibernate.ddl-auto=create
5 | spring.datasource.initialize=true
6 |
--------------------------------------------------------------------------------
/actors/src/main/resources/application-kubernetes.properties:
--------------------------------------------------------------------------------
1 | endpoints.env.enabled=true
2 | spring.jpa.hibernate.ddl-auto=update
3 | spring.datasource.initialize=false
4 |
--------------------------------------------------------------------------------
/actors/src/test/java/com/springdeveloper/k8s/actors/ActorsApplicationTests.java:
--------------------------------------------------------------------------------
1 | package com.springdeveloper.k8s.actors;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.springframework.boot.test.context.SpringBootTest;
6 | import org.springframework.test.context.junit4.SpringRunner;
7 |
8 | @RunWith(SpringRunner.class)
9 | @SpringBootTest
10 | public class ActorsApplicationTests {
11 |
12 | @Test
13 | public void contextLoads() {
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/demo-actors.adoc:
--------------------------------------------------------------------------------
1 | == Demo - Actors Microservice for Kubernetes
2 |
3 | A Simple REST Repository App for managing Actors
4 |
5 | ==== Create the app and the config for local testing
6 |
7 | . Create a small CRUD JPA Repository app
8 | +
9 | ----
10 | curl https://start.spring.io/starter.zip -d bootVersion=2.0.0.M5 \
11 | -d dependencies=web,actuator,jpa,data-rest,mysql,hsql \
12 | -d groupId=com.springdeveloper.k8s -d artifactId=actors \
13 | -d name=actors -d baseDir=actors -o actors.zip
14 | unzip actors.zip
15 | cd actors
16 | ----
17 |
18 | . Add an Actor Entity
19 | +
20 | .Actor.java
21 | [source,java]
22 | ----
23 | package com.springdeveloper.k8s.actors;
24 |
25 | import javax.persistence.Entity;
26 | import javax.persistence.GeneratedValue;
27 | import javax.persistence.Id;
28 |
29 | @Entity
30 | public class Actor {
31 |
32 | @Id
33 | @GeneratedValue
34 | Long id;
35 |
36 | String name;
37 |
38 | int age;
39 |
40 | public Long getId() {
41 | return id;
42 | }
43 |
44 | public String getName() {
45 | return name;
46 | }
47 |
48 | public void setName(String name) {
49 | this.name = name;
50 | }
51 |
52 | public int getAge() {
53 | return age;
54 | }
55 |
56 | public void setAge(int age) {
57 | this.age = age;
58 | }
59 | }
60 | ----
61 |
62 | . Add an ActorRepository
63 | +
64 | .ActorRepository.java
65 | [source,java]
66 | ----
67 | package com.springdeveloper.k8s.actors;
68 |
69 | import java.util.List;
70 |
71 | import org.springframework.data.repository.PagingAndSortingRepository;
72 | import org.springframework.data.repository.query.Param;
73 |
74 | public interface ActorRepository extends PagingAndSortingRepository {
75 |
76 | List findByName(@Param("name") String name);
77 |
78 | }
79 | ----
80 |
81 | . Create default properties file for running app locally
82 | +
83 | .application-default.properties
84 | [source,props]
85 | ----
86 | endpoints.env.enabled=true
87 | spring.datasource.url=jdbc:hsqldb:file:target/testdb
88 | spring.datasource.username=sa
89 | spring.jpa.hibernate.ddl-auto=create
90 | spring.datasource.initialize=true
91 | ----
92 |
93 | . Build and run the app locally
94 | +
95 | ----
96 | ./mvnw clean package
97 | java -jar target/actors-0.0.1-SNAPSHOT.jar
98 | ----
99 |
100 | . You can add actor records:
101 | +
102 | ----
103 | curl -i -X POST -H "Content-Type:application/json" -d "{ \"name\" : \"Dolph Lundgren\", \"age\" : 59 }" http://localhost:8080/actors
104 | ----
105 |
106 | . Test
107 | +
108 | ----
109 | curl http://localhost:8080/actors | python -m json.tool
110 | ----
111 |
112 | ==== Create a MySQL database deployment and service
113 |
114 | . Configure a MySQL deployment and service
115 | +
116 | .mysql/mysql-deployment.yaml
117 | [source,yaml]
118 | ----
119 | apiVersion: extensions/v1beta1
120 | kind: Deployment
121 | metadata:
122 | name: mysql
123 | labels:
124 | app: mysql
125 | spec:
126 | replicas: 1
127 | template:
128 | metadata:
129 | labels:
130 | app: mysql
131 | spec:
132 | containers:
133 | - image: mysql:5.6
134 | name: mysql
135 | env:
136 | - name: MYSQL_ROOT_PASSWORD
137 | # You can change this password - if you do change the base64 encoded value in the secrets file
138 | value: yourpassword
139 | ports:
140 | - containerPort: 3306
141 | name: mysql
142 | volumeMounts:
143 | - name: data
144 | mountPath: /var/lib/mysql
145 | volumes:
146 | - name: data
147 | persistentVolumeClaim:
148 | claimName: mysql
149 | ----
150 | +
151 | .mysql/mysql-svc.yaml
152 | [source,yaml]
153 | ----
154 | apiVersion: v1
155 | kind: Service
156 | metadata:
157 | name: mysql
158 | labels:
159 | app: mysql
160 | spec:
161 | ports:
162 | - port: 3306
163 | selector:
164 | app: mysql
165 | ----
166 | +
167 | .mysql/mysql-pvc.yaml
168 | [source,yaml]
169 | ----
170 | apiVersion: v1
171 | kind: PersistentVolumeClaim
172 | metadata:
173 | name: mysql
174 | labels:
175 | app: mysql
176 | annotations:
177 | volume.alpha.kubernetes.io/storage-class: default
178 | spec:
179 | accessModes:
180 | - ReadWriteOnce
181 | resources:
182 | requests:
183 | storage: 8Gi
184 | ----
185 | +
186 | .mysql/mysql-secrets.yaml
187 | [source,yaml]
188 | ----
189 | apiVersion: v1
190 | kind: Secret
191 | metadata:
192 | name: mysql
193 | labels:
194 | app: mysql
195 | data:
196 | mysql-root-password: eW91cnBhc3N3b3Jk
197 | ----
198 |
199 | . Deploy the MySQL database
200 | +
201 | ----
202 | kubectl apply -f ./mysql/
203 | ----
204 |
205 | ==== Add Kubernetes configuration
206 |
207 | . Add config properties for running on Kubernetes
208 | +
209 | .application-kubernetes.properties
210 | [source,props]
211 | ----
212 | endpoints.env.enabled=true
213 | spring.jpa.hibernate.ddl-auto=update
214 | spring.datasource.initialize=false
215 | ----
216 |
217 | . Add `Dockerfile` and Docker Maven plug-in to the `pom.xml`. We are using the most recent https://github.com/spotify/dockerfile-maven[Spotify plugin].
218 | +
219 | .Dockerfile
220 | [source]
221 | ----
222 | FROM java:8-alpine
223 | VOLUME /tmp
224 | ARG JAR_FILE
225 | ADD ./target/${JAR_FILE} /actors.jar
226 | RUN sh -c 'touch /actors.jar'
227 | ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/actors.jar"]
228 | ----
229 | +
230 | .pom.xml
231 | [source,xml]
232 | ----
233 | ...
234 |
235 |
236 | ...
237 |
238 | com.spotify
239 | dockerfile-maven-plugin
240 | 1.3.6
241 |
242 | ${user.name}/${project.artifactId}
243 | ${project.version}
244 |
245 | ${project.build.finalName}.jar
246 |
247 |
248 |
249 | ...
250 |
251 |
252 | ...
253 | ----
254 |
255 | . Downgrade Hibernate version
256 | +
257 | WARNING: We need to downgrade the Hibernate version. The most recent version throws an error when using "spring.jpa.hibernate.ddl-auto=update" and the tables already exist.
258 | +
259 | .pom.xml
260 | [source,xml]
261 | ----
262 | ...
263 |
264 |
265 | org.hibernate
266 | hibernate-core
267 | 4.3.10.Final
268 |
269 |
270 | org.hibernate
271 | hibernate-entitymanager
272 | 4.3.10.Final
273 |
274 | ...
275 | ----
276 |
277 | . Create the Kubernetes configuration files for the app
278 | +
279 | .config/actors-svc.yaml
280 | [source,yaml]
281 | ----
282 | kind: Service
283 | apiVersion: v1
284 | metadata:
285 | name: actors
286 | labels:
287 | app: actors
288 | spec:
289 | # If you are running k8s on a local dev box or using minikube, you can use type NodePort instead of LoadBalancer
290 | type: NodePort
291 | ports:
292 | - port: 80
293 | selector:
294 | app: actors
295 | ----
296 | +
297 | .config/actors-deployment.yaml
298 | [source,yaml]
299 | ----
300 | apiVersion: extensions/v1beta1
301 | kind: Deployment
302 | metadata:
303 | name: actors
304 | labels:
305 | app: actors
306 | spec:
307 | replicas: 1
308 | template:
309 | metadata:
310 | labels:
311 | app: actors
312 | spec:
313 | containers:
314 | - name: actors
315 | image: trisberg/actors:0.0.1-SNAPSHOT
316 | imagePullPolicy: IfNotPresent
317 | ports:
318 | - containerPort: 80
319 | resources:
320 | limits:
321 | cpu: 1.0
322 | memory: 1024Mi
323 | requests:
324 | cpu: 0.5
325 | memory: 640Mi
326 | livenessProbe:
327 | httpGet:
328 | path: /application/status
329 | port: 80
330 | initialDelaySeconds: 90
331 | periodSeconds: 15
332 | timeoutSeconds: 5
333 | readinessProbe:
334 | httpGet:
335 | path: /application/status
336 | port: 80
337 | initialDelaySeconds: 45
338 | periodSeconds: 15
339 | timeoutSeconds: 5
340 | env:
341 | - name: SERVER_PORT
342 | value: '80'
343 | - name: SPRING_PROFILES_ACTIVE
344 | value: kubernetes
345 | - name: MYSQL_ROOT_PASSWORD
346 | valueFrom:
347 | secretKeyRef:
348 | name: mysql
349 | key: mysql-root-password
350 | volumeMounts:
351 | - name: application-config
352 | mountPath: "/config"
353 | readOnly: true
354 | volumes:
355 | - name: application-config
356 | configMap:
357 | name: actors
358 | items:
359 | - key: application.yaml
360 | path: application-kubernetes.yaml
361 | ----
362 | +
363 | .config/actors-config.yaml
364 | [source,yaml]
365 | ----
366 | apiVersion: v1
367 | kind: ConfigMap
368 | metadata:
369 | name: actors
370 | labels:
371 | app: actors
372 | data:
373 | application.yaml: |-
374 | security:
375 | basic:
376 | enabled: false
377 | spring:
378 | datasource:
379 | url: jdbc:mysql://${MYSQL_SERVICE_HOST}:${MYSQL_SERVICE_PORT}/mysql
380 | username: root
381 | password: ${mysql-root-password}
382 | driverClassName: com.mysql.jdbc.Driver
383 | testOnBorrow: true
384 | validationQuery: "SELECT 1"
385 | ----
386 |
387 | ==== Deploy app on Kubernetes and test
388 |
389 | . Build app and Docker image
390 | +
391 | NOTE: We are sharing the Docker environment used by Minikube
392 | +
393 | ----
394 | eval $(minikube docker-env)
395 | ./mvnw clean package dockerfile:build
396 | ----
397 |
398 | . Deploy app to k8s
399 | +
400 | ----
401 | kubectl apply -f config/
402 | ----
403 |
404 | . Get status
405 | +
406 | ----
407 | $ kubectl get all
408 | ----
409 |
410 | . Add some actor records
411 | +
412 | We need to look up the IP address of the service and then POST some data to it and test retreiving them:
413 | +
414 | [source,bash]
415 | ----
416 | export ACTORS_URL="$(minikube service actors --url)"
417 | curl -i -X POST -H "Content-Type:application/json" -d "{ \"name\" : \"Dolph Lundgren\", \"age\" : 59 }" $ACTORS_URL/actors
418 | curl -i -X POST -H "Content-Type:application/json" -d "{ \"name\" : \"Jack Nicholson\", \"age\" : 80 }" $ACTORS_URL/actors
419 | curl -i -X POST -H "Content-Type:application/json" -d "{ \"name\" : \"Meryl Streep\", \"age\" : 68 }" $ACTORS_URL/actors
420 | curl $ACTORS_URL/actors
421 | ----
422 |
--------------------------------------------------------------------------------
/demo-hello.adoc:
--------------------------------------------------------------------------------
1 | == Demo - Hello App deployed on Kubernetes
2 |
3 | Simple Hello Spring Boot app deployment on Minikube
4 |
5 | ==== Start Minikube
6 |
7 | - Install Minikube from https://kubernetes.io/docs/tasks/tools/install-minikube/
8 |
9 | - Install `kubectl` from https://kubernetes.io/docs/tasks/tools/install-kubectl/
10 |
11 | Then, start Minikube:
12 |
13 | minikube start
14 |
15 | ==== Create and run a simple Spring Boot app
16 |
17 | . Create a simple Boot app (You can also use https://start.spring.io/[Spring Initializr] web interface)
18 | +
19 | ----
20 | curl https://start.spring.io/starter.zip -d bootVersion=2.0.0.M5 \
21 | -d dependencies=web,actuator \
22 | -d groupId=com.springdeveloper.k8s -d artifactId=hello \
23 | -d name=hello -d baseDir=hello -o hello.zip
24 | unzip hello.zip
25 | cd hello
26 | ----
27 |
28 | NOTE: We are using the most Spring Boot 2.0 M5, as of Nov 6 there is a new M6 milestone available.
29 |
30 | . Add a `@RestController` and a mapping for `/hello` (the bold parts are the additions):
31 | +
32 | .src/main/java/com/springdeveloper/k8s/demo/HelloApplication.java
33 | [source,subs=+quotes]
34 | ----
35 | package com.springdeveloper.k8s.hello;
36 |
37 | import org.springframework.boot.SpringApplication;
38 | import org.springframework.boot.autoconfigure.SpringBootApplication;
39 | *import org.springframework.web.bind.annotation.GetMapping;*
40 | *import org.springframework.web.bind.annotation.RestController;*
41 |
42 | @SpringBootApplication
43 | public class HelloApplication {
44 | public static void main(String[] args) {
45 | SpringApplication.run(HelloApplication.class, args);
46 | }
47 |
48 | *@RestController*
49 | *class HelloController {*
50 | *@GetMapping("/hello")*
51 | *String hello() {*
52 | *return "Hello Kubernauts!";*
53 | *}*
54 | *}*
55 | }
56 | ----
57 |
58 | . Add a property enabling the `/application/env` endpoint. This allows us to inspect environment variables added by Kubernetes.
59 | +
60 | .src/main/resources/application.properties
61 | ----
62 | endpoints.env.enabled=true
63 | ----
64 |
65 | . Create a `Dockerfile` so we can package this app as a Docker image
66 | +
67 | .Dockerfile
68 | ----
69 | FROM java:8-alpine
70 | VOLUME /tmp
71 | ADD ./target/hello-0.0.1-SNAPSHOT.jar /hello.jar
72 | RUN sh -c 'touch /hello.jar'
73 | ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/hello.jar"]
74 | ----
75 |
76 | . Build the app and the Docker image
77 | +
78 | NOTE: We are sharing the Docker environment used by Minikube
79 | +
80 | ----
81 | eval $(minikube docker-env)
82 | ./mvnw clean package
83 | docker build -t $USER/hello:0.0.1 .
84 | ----
85 |
86 | . Run a Kubernetes deployment on the running Minikube cluster
87 | +
88 | ----
89 | kubectl run hello --image $USER/hello:0.0.1 --port 8080
90 | kubectl expose deployment hello --type=NodePort
91 | ----
92 |
93 | . Test the app
94 | +
95 | ----
96 | curl $(minikube service hello --url)/hello
97 | ----
98 |
99 | . Inspect environment variables and Kubernetes deployment/service yaml
100 | +
101 | ----
102 | curl $(minikube service hello --url)/application/env | python -m json.tool
103 | kubectl get deploy/hello -o yaml
104 | kubectl get svc/hello -o yaml
105 | ----
106 |
107 | . Create Deployment and Service YAML files for future repeatable deployments
108 | +
109 | ProTip from Joe Beda at Heptio: https://blog.heptio.com/using-kubectl-to-jumpstart-a-yaml-file-heptioprotip-6f5b8a63a3ea
110 | +
111 | ----
112 | kubectl run hello --image $USER/hello:0.0.1 --port 8080 -o yaml --dry-run \
113 | > hello-deployment.yaml
114 | kubectl expose deployment hello --type=NodePort -o yaml --dry-run > hello-svc.yaml
115 | ----
116 |
117 | . Delete the resources created for `hello`
118 | +
119 | ----
120 | kubectl delete all -l run=hello
121 | ----
122 |
--------------------------------------------------------------------------------
/demo-microservices.adoc:
--------------------------------------------------------------------------------
1 | == Demo - Spring Boot Microservices on Kubernetes
2 |
3 | See: https://github.com/trisberg/boot-k8s-microservices/blob/devoxx-2017/README.adoc[]
4 |
5 |
6 |
--------------------------------------------------------------------------------
/hello/.gitignore:
--------------------------------------------------------------------------------
1 | target/
2 | !.mvn/wrapper/maven-wrapper.jar
3 |
4 | ### STS ###
5 | .apt_generated
6 | .classpath
7 | .factorypath
8 | .project
9 | .settings
10 | .springBeans
11 |
12 | ### IntelliJ IDEA ###
13 | .idea
14 | *.iws
15 | *.iml
16 | *.ipr
17 |
18 | ### NetBeans ###
19 | nbproject/private/
20 | build/
21 | nbbuild/
22 | dist/
23 | nbdist/
24 | .nb-gradle/
--------------------------------------------------------------------------------
/hello/.mvn/wrapper/maven-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/trisberg/devoxx-spring-boot-k8s/02dd60d3d9005bc956fe3c794f89eddcf0ce975f/hello/.mvn/wrapper/maven-wrapper.jar
--------------------------------------------------------------------------------
/hello/.mvn/wrapper/maven-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.0/apache-maven-3.5.0-bin.zip
2 |
--------------------------------------------------------------------------------
/hello/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM java:8-alpine
2 | VOLUME /tmp
3 | ADD ./target/hello-0.0.1-SNAPSHOT.jar /hello.jar
4 | RUN sh -c 'touch /hello.jar'
5 | ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/hello.jar"]
6 |
--------------------------------------------------------------------------------
/hello/hello-deployment.yaml:
--------------------------------------------------------------------------------
1 | apiVersion: extensions/v1beta1
2 | kind: Deployment
3 | metadata:
4 | creationTimestamp: null
5 | labels:
6 | run: hello
7 | name: hello
8 | spec:
9 | replicas: 1
10 | selector:
11 | matchLabels:
12 | run: hello
13 | strategy: {}
14 | template:
15 | metadata:
16 | creationTimestamp: null
17 | labels:
18 | run: hello
19 | spec:
20 | containers:
21 | - image: trisberg/hello:0.0.1
22 | name: hello
23 | ports:
24 | - containerPort: 8080
25 | resources: {}
26 | status: {}
27 |
--------------------------------------------------------------------------------
/hello/hello-svc.yaml:
--------------------------------------------------------------------------------
1 | apiVersion: v1
2 | kind: Service
3 | metadata:
4 | creationTimestamp: null
5 | labels:
6 | run: hello
7 | name: hello
8 | spec:
9 | ports:
10 | - port: 8080
11 | protocol: TCP
12 | targetPort: 8080
13 | selector:
14 | run: hello
15 | type: NodePort
16 | status:
17 | loadBalancer: {}
18 |
--------------------------------------------------------------------------------
/hello/mvnw:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | # ----------------------------------------------------------------------------
3 | # Licensed to the Apache Software Foundation (ASF) under one
4 | # or more contributor license agreements. See the NOTICE file
5 | # distributed with this work for additional information
6 | # regarding copyright ownership. The ASF licenses this file
7 | # to you under the Apache License, Version 2.0 (the
8 | # "License"); you may not use this file except in compliance
9 | # with the License. You may obtain a copy of the License at
10 | #
11 | # http://www.apache.org/licenses/LICENSE-2.0
12 | #
13 | # Unless required by applicable law or agreed to in writing,
14 | # software distributed under the License is distributed on an
15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 | # KIND, either express or implied. See the License for the
17 | # specific language governing permissions and limitations
18 | # under the License.
19 | # ----------------------------------------------------------------------------
20 |
21 | # ----------------------------------------------------------------------------
22 | # Maven2 Start Up Batch script
23 | #
24 | # Required ENV vars:
25 | # ------------------
26 | # JAVA_HOME - location of a JDK home dir
27 | #
28 | # Optional ENV vars
29 | # -----------------
30 | # M2_HOME - location of maven2's installed home dir
31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven
32 | # e.g. to debug Maven itself, use
33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files
35 | # ----------------------------------------------------------------------------
36 |
37 | if [ -z "$MAVEN_SKIP_RC" ] ; then
38 |
39 | if [ -f /etc/mavenrc ] ; then
40 | . /etc/mavenrc
41 | fi
42 |
43 | if [ -f "$HOME/.mavenrc" ] ; then
44 | . "$HOME/.mavenrc"
45 | fi
46 |
47 | fi
48 |
49 | # OS specific support. $var _must_ be set to either true or false.
50 | cygwin=false;
51 | darwin=false;
52 | mingw=false
53 | case "`uname`" in
54 | CYGWIN*) cygwin=true ;;
55 | MINGW*) mingw=true;;
56 | Darwin*) darwin=true
57 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home
58 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html
59 | if [ -z "$JAVA_HOME" ]; then
60 | if [ -x "/usr/libexec/java_home" ]; then
61 | export JAVA_HOME="`/usr/libexec/java_home`"
62 | else
63 | export JAVA_HOME="/Library/Java/Home"
64 | fi
65 | fi
66 | ;;
67 | esac
68 |
69 | if [ -z "$JAVA_HOME" ] ; then
70 | if [ -r /etc/gentoo-release ] ; then
71 | JAVA_HOME=`java-config --jre-home`
72 | fi
73 | fi
74 |
75 | if [ -z "$M2_HOME" ] ; then
76 | ## resolve links - $0 may be a link to maven's home
77 | PRG="$0"
78 |
79 | # need this for relative symlinks
80 | while [ -h "$PRG" ] ; do
81 | ls=`ls -ld "$PRG"`
82 | link=`expr "$ls" : '.*-> \(.*\)$'`
83 | if expr "$link" : '/.*' > /dev/null; then
84 | PRG="$link"
85 | else
86 | PRG="`dirname "$PRG"`/$link"
87 | fi
88 | done
89 |
90 | saveddir=`pwd`
91 |
92 | M2_HOME=`dirname "$PRG"`/..
93 |
94 | # make it fully qualified
95 | M2_HOME=`cd "$M2_HOME" && pwd`
96 |
97 | cd "$saveddir"
98 | # echo Using m2 at $M2_HOME
99 | fi
100 |
101 | # For Cygwin, ensure paths are in UNIX format before anything is touched
102 | if $cygwin ; then
103 | [ -n "$M2_HOME" ] &&
104 | M2_HOME=`cygpath --unix "$M2_HOME"`
105 | [ -n "$JAVA_HOME" ] &&
106 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
107 | [ -n "$CLASSPATH" ] &&
108 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
109 | fi
110 |
111 | # For Migwn, ensure paths are in UNIX format before anything is touched
112 | if $mingw ; then
113 | [ -n "$M2_HOME" ] &&
114 | M2_HOME="`(cd "$M2_HOME"; pwd)`"
115 | [ -n "$JAVA_HOME" ] &&
116 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`"
117 | # TODO classpath?
118 | fi
119 |
120 | if [ -z "$JAVA_HOME" ]; then
121 | javaExecutable="`which javac`"
122 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then
123 | # readlink(1) is not available as standard on Solaris 10.
124 | readLink=`which readlink`
125 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then
126 | if $darwin ; then
127 | javaHome="`dirname \"$javaExecutable\"`"
128 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac"
129 | else
130 | javaExecutable="`readlink -f \"$javaExecutable\"`"
131 | fi
132 | javaHome="`dirname \"$javaExecutable\"`"
133 | javaHome=`expr "$javaHome" : '\(.*\)/bin'`
134 | JAVA_HOME="$javaHome"
135 | export JAVA_HOME
136 | fi
137 | fi
138 | fi
139 |
140 | if [ -z "$JAVACMD" ] ; then
141 | if [ -n "$JAVA_HOME" ] ; then
142 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
143 | # IBM's JDK on AIX uses strange locations for the executables
144 | JAVACMD="$JAVA_HOME/jre/sh/java"
145 | else
146 | JAVACMD="$JAVA_HOME/bin/java"
147 | fi
148 | else
149 | JAVACMD="`which java`"
150 | fi
151 | fi
152 |
153 | if [ ! -x "$JAVACMD" ] ; then
154 | echo "Error: JAVA_HOME is not defined correctly." >&2
155 | echo " We cannot execute $JAVACMD" >&2
156 | exit 1
157 | fi
158 |
159 | if [ -z "$JAVA_HOME" ] ; then
160 | echo "Warning: JAVA_HOME environment variable is not set."
161 | fi
162 |
163 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
164 |
165 | # traverses directory structure from process work directory to filesystem root
166 | # first directory with .mvn subdirectory is considered project base directory
167 | find_maven_basedir() {
168 |
169 | if [ -z "$1" ]
170 | then
171 | echo "Path not specified to find_maven_basedir"
172 | return 1
173 | fi
174 |
175 | basedir="$1"
176 | wdir="$1"
177 | while [ "$wdir" != '/' ] ; do
178 | if [ -d "$wdir"/.mvn ] ; then
179 | basedir=$wdir
180 | break
181 | fi
182 | # workaround for JBEAP-8937 (on Solaris 10/Sparc)
183 | if [ -d "${wdir}" ]; then
184 | wdir=`cd "$wdir/.."; pwd`
185 | fi
186 | # end of workaround
187 | done
188 | echo "${basedir}"
189 | }
190 |
191 | # concatenates all lines of a file
192 | concat_lines() {
193 | if [ -f "$1" ]; then
194 | echo "$(tr -s '\n' ' ' < "$1")"
195 | fi
196 | }
197 |
198 | BASE_DIR=`find_maven_basedir "$(pwd)"`
199 | if [ -z "$BASE_DIR" ]; then
200 | exit 1;
201 | fi
202 |
203 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}
204 | echo $MAVEN_PROJECTBASEDIR
205 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
206 |
207 | # For Cygwin, switch paths to Windows format before running java
208 | if $cygwin; then
209 | [ -n "$M2_HOME" ] &&
210 | M2_HOME=`cygpath --path --windows "$M2_HOME"`
211 | [ -n "$JAVA_HOME" ] &&
212 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
213 | [ -n "$CLASSPATH" ] &&
214 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
215 | [ -n "$MAVEN_PROJECTBASEDIR" ] &&
216 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"`
217 | fi
218 |
219 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
220 |
221 | exec "$JAVACMD" \
222 | $MAVEN_OPTS \
223 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
224 | "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
225 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@"
226 |
--------------------------------------------------------------------------------
/hello/mvnw.cmd:
--------------------------------------------------------------------------------
1 | @REM ----------------------------------------------------------------------------
2 | @REM Licensed to the Apache Software Foundation (ASF) under one
3 | @REM or more contributor license agreements. See the NOTICE file
4 | @REM distributed with this work for additional information
5 | @REM regarding copyright ownership. The ASF licenses this file
6 | @REM to you under the Apache License, Version 2.0 (the
7 | @REM "License"); you may not use this file except in compliance
8 | @REM with the License. You may obtain a copy of the License at
9 | @REM
10 | @REM http://www.apache.org/licenses/LICENSE-2.0
11 | @REM
12 | @REM Unless required by applicable law or agreed to in writing,
13 | @REM software distributed under the License is distributed on an
14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | @REM KIND, either express or implied. See the License for the
16 | @REM specific language governing permissions and limitations
17 | @REM under the License.
18 | @REM ----------------------------------------------------------------------------
19 |
20 | @REM ----------------------------------------------------------------------------
21 | @REM Maven2 Start Up Batch script
22 | @REM
23 | @REM Required ENV vars:
24 | @REM JAVA_HOME - location of a JDK home dir
25 | @REM
26 | @REM Optional ENV vars
27 | @REM M2_HOME - location of maven2's installed home dir
28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands
29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending
30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven
31 | @REM e.g. to debug Maven itself, use
32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files
34 | @REM ----------------------------------------------------------------------------
35 |
36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on'
37 | @echo off
38 | @REM enable echoing my setting MAVEN_BATCH_ECHO to 'on'
39 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO%
40 |
41 | @REM set %HOME% to equivalent of $HOME
42 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%")
43 |
44 | @REM Execute a user defined script before this one
45 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre
46 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending
47 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat"
48 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd"
49 | :skipRcPre
50 |
51 | @setlocal
52 |
53 | set ERROR_CODE=0
54 |
55 | @REM To isolate internal variables from possible post scripts, we use another setlocal
56 | @setlocal
57 |
58 | @REM ==== START VALIDATION ====
59 | if not "%JAVA_HOME%" == "" goto OkJHome
60 |
61 | echo.
62 | echo Error: JAVA_HOME not found in your environment. >&2
63 | echo Please set the JAVA_HOME variable in your environment to match the >&2
64 | echo location of your Java installation. >&2
65 | echo.
66 | goto error
67 |
68 | :OkJHome
69 | if exist "%JAVA_HOME%\bin\java.exe" goto init
70 |
71 | echo.
72 | echo Error: JAVA_HOME is set to an invalid directory. >&2
73 | echo JAVA_HOME = "%JAVA_HOME%" >&2
74 | echo Please set the JAVA_HOME variable in your environment to match the >&2
75 | echo location of your Java installation. >&2
76 | echo.
77 | goto error
78 |
79 | @REM ==== END VALIDATION ====
80 |
81 | :init
82 |
83 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn".
84 | @REM Fallback to current working directory if not found.
85 |
86 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR%
87 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir
88 |
89 | set EXEC_DIR=%CD%
90 | set WDIR=%EXEC_DIR%
91 | :findBaseDir
92 | IF EXIST "%WDIR%"\.mvn goto baseDirFound
93 | cd ..
94 | IF "%WDIR%"=="%CD%" goto baseDirNotFound
95 | set WDIR=%CD%
96 | goto findBaseDir
97 |
98 | :baseDirFound
99 | set MAVEN_PROJECTBASEDIR=%WDIR%
100 | cd "%EXEC_DIR%"
101 | goto endDetectBaseDir
102 |
103 | :baseDirNotFound
104 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR%
105 | cd "%EXEC_DIR%"
106 |
107 | :endDetectBaseDir
108 |
109 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig
110 |
111 | @setlocal EnableExtensions EnableDelayedExpansion
112 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a
113 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS%
114 |
115 | :endReadAdditionalConfig
116 |
117 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe"
118 |
119 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar"
120 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
121 |
122 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %*
123 | if ERRORLEVEL 1 goto error
124 | goto end
125 |
126 | :error
127 | set ERROR_CODE=1
128 |
129 | :end
130 | @endlocal & set ERROR_CODE=%ERROR_CODE%
131 |
132 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost
133 | @REM check for post script, once with legacy .bat ending and once with .cmd ending
134 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat"
135 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd"
136 | :skipRcPost
137 |
138 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on'
139 | if "%MAVEN_BATCH_PAUSE%" == "on" pause
140 |
141 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE%
142 |
143 | exit /B %ERROR_CODE%
144 |
--------------------------------------------------------------------------------
/hello/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | com.springdeveloper.k8s
7 | hello
8 | 0.0.1-SNAPSHOT
9 | jar
10 |
11 | hello
12 | Demo project for Spring Boot
13 |
14 |
15 | org.springframework.boot
16 | spring-boot-starter-parent
17 | 2.0.0.M5
18 |
19 |
20 |
21 |
22 | UTF-8
23 | UTF-8
24 | 1.8
25 |
26 |
27 |
28 |
29 | org.springframework.boot
30 | spring-boot-starter-actuator
31 |
32 |
33 | org.springframework.boot
34 | spring-boot-starter-web
35 |
36 |
37 |
38 | org.springframework.boot
39 | spring-boot-starter-test
40 | test
41 |
42 |
43 |
44 |
45 |
46 |
47 | org.springframework.boot
48 | spring-boot-maven-plugin
49 |
50 |
51 |
52 |
53 |
54 |
55 | spring-snapshots
56 | Spring Snapshots
57 | https://repo.spring.io/snapshot
58 |
59 | true
60 |
61 |
62 |
63 | spring-milestones
64 | Spring Milestones
65 | https://repo.spring.io/milestone
66 |
67 | false
68 |
69 |
70 |
71 |
72 |
73 |
74 | spring-snapshots
75 | Spring Snapshots
76 | https://repo.spring.io/snapshot
77 |
78 | true
79 |
80 |
81 |
82 | spring-milestones
83 | Spring Milestones
84 | https://repo.spring.io/milestone
85 |
86 | false
87 |
88 |
89 |
90 |
91 |
92 |
93 |
--------------------------------------------------------------------------------
/hello/src/main/java/com/springdeveloper/k8s/hello/HelloApplication.java:
--------------------------------------------------------------------------------
1 | package com.springdeveloper.k8s.hello;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 | import org.springframework.web.bind.annotation.GetMapping;
6 | import org.springframework.web.bind.annotation.RestController;
7 |
8 | @SpringBootApplication
9 | public class HelloApplication {
10 |
11 | @RestController
12 | class HelloController {
13 | @GetMapping("/hello")
14 | String hello() {
15 | return "Hello Kubernauts!";
16 | }
17 | }
18 |
19 | public static void main(String[] args) {
20 | SpringApplication.run(HelloApplication.class, args);
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/hello/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | endpoints.env.enabled=true
2 |
--------------------------------------------------------------------------------
/hello/src/test/java/com/springdeveloper/k8s/hello/HelloApplicationTests.java:
--------------------------------------------------------------------------------
1 | package com.springdeveloper.k8s.hello;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.springframework.boot.test.context.SpringBootTest;
6 | import org.springframework.test.context.junit4.SpringRunner;
7 |
8 | @RunWith(SpringRunner.class)
9 | @SpringBootTest
10 | public class HelloApplicationTests {
11 |
12 | @Test
13 | public void contextLoads() {
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/mysql/mysql-deployment.yaml:
--------------------------------------------------------------------------------
1 | apiVersion: extensions/v1beta1
2 | kind: Deployment
3 | metadata:
4 | name: mysql
5 | labels:
6 | app: mysql
7 | spec:
8 | replicas: 1
9 | template:
10 | metadata:
11 | labels:
12 | app: mysql
13 | spec:
14 | containers:
15 | - image: mysql:5.6
16 | name: mysql
17 | env:
18 | - name: MYSQL_ROOT_PASSWORD
19 | # You can change this password - if you do change the base64 encoded value in the secrets file
20 | value: yourpassword
21 | ports:
22 | - containerPort: 3306
23 | name: mysql
24 | volumeMounts:
25 | - name: data
26 | mountPath: /var/lib/mysql
27 | volumes:
28 | - name: data
29 | persistentVolumeClaim:
30 | claimName: mysql
31 |
--------------------------------------------------------------------------------
/mysql/mysql-pvc.yaml:
--------------------------------------------------------------------------------
1 | apiVersion: v1
2 | kind: PersistentVolumeClaim
3 | metadata:
4 | name: mysql
5 | labels:
6 | app: mysql
7 | annotations:
8 | volume.alpha.kubernetes.io/storage-class: default
9 | spec:
10 | accessModes:
11 | - ReadWriteOnce
12 | resources:
13 | requests:
14 | storage: 8Gi
15 |
--------------------------------------------------------------------------------
/mysql/mysql-secrets.yaml:
--------------------------------------------------------------------------------
1 | apiVersion: v1
2 | kind: Secret
3 | metadata:
4 | name: mysql
5 | labels:
6 | app: mysql
7 | data:
8 | mysql-root-password: eW91cnBhc3N3b3Jk
9 |
--------------------------------------------------------------------------------
/mysql/mysql-svc.yaml:
--------------------------------------------------------------------------------
1 | apiVersion: v1
2 | kind: Service
3 | metadata:
4 | name: mysql
5 | labels:
6 | app: mysql
7 | spec:
8 | ports:
9 | - port: 3306
10 | selector:
11 | app: mysql
12 |
--------------------------------------------------------------------------------