Skip to content

Commit 08ab93c

Browse files
committed
Adding Kustomize example app
1 parent 3aaf059 commit 08ab93c

19 files changed

+259
-0
lines changed

kustomize-app/.DS_Store

6 KB
Binary file not shown.

kustomize-app/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This is a sample Kustomize application that includes both a base and overlays folder with both Staging and Production environments.

kustomize-app/app/Dockerfile

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FROM maven:3.6.1-jdk-8-alpine AS MAVEN_BUILD
2+
3+
COPY ./ ./
4+
5+
RUN mvn clean package
6+
7+
FROM openjdk:8-jre-alpine3.9
8+
9+
COPY --from=MAVEN_BUILD /target/spring-boot-0.0.1-SNAPSHOT.jar /demo.jar
10+
11+
CMD ["java", "-jar", "/demo.jar"]

kustomize-app/app/pom.xml

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<parent>
6+
<groupId>org.springframework.boot</groupId>
7+
<artifactId>spring-boot-starter-parent</artifactId>
8+
<version>2.2.2.RELEASE</version>
9+
<relativePath/> <!-- lookup parent from repository -->
10+
</parent>
11+
<groupId>com.example</groupId>
12+
<artifactId>spring-boot</artifactId>
13+
<version>0.0.1-SNAPSHOT</version>
14+
<name>spring-boot</name>
15+
<description>Demo project for Spring Boot</description>
16+
17+
<properties>
18+
<java.version>1.8</java.version>
19+
</properties>
20+
21+
<dependencies>
22+
<dependency>
23+
<groupId>org.springframework.boot</groupId>
24+
<artifactId>spring-boot-starter-web</artifactId>
25+
</dependency>
26+
27+
<!-- tag::actuator[] -->
28+
<dependency>
29+
<groupId>org.springframework.boot</groupId>
30+
<artifactId>spring-boot-starter-actuator</artifactId>
31+
</dependency>
32+
<!-- end::actuator[] -->
33+
34+
<!-- tag::tests[] -->
35+
<dependency>
36+
<groupId>org.springframework.boot</groupId>
37+
<artifactId>spring-boot-starter-test</artifactId>
38+
<scope>test</scope>
39+
<exclusions>
40+
<exclusion>
41+
<groupId>org.junit.vintage</groupId>
42+
<artifactId>junit-vintage-engine</artifactId>
43+
</exclusion>
44+
</exclusions>
45+
</dependency>
46+
<!-- end::tests[] -->
47+
</dependencies>
48+
49+
<build>
50+
<plugins>
51+
<plugin>
52+
<groupId>org.springframework.boot</groupId>
53+
<artifactId>spring-boot-maven-plugin</artifactId>
54+
</plugin>
55+
</plugins>
56+
</build>
57+
58+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.example.springboot;
2+
3+
import java.util.Arrays;
4+
5+
import org.springframework.boot.CommandLineRunner;
6+
import org.springframework.boot.SpringApplication;
7+
import org.springframework.boot.autoconfigure.SpringBootApplication;
8+
import org.springframework.context.ApplicationContext;
9+
import org.springframework.context.annotation.Bean;
10+
11+
@SpringBootApplication
12+
public class Application {
13+
14+
public static void main(String[] args) {
15+
SpringApplication.run(Application.class, args);
16+
}
17+
18+
@Bean
19+
public CommandLineRunner commandLineRunner(ApplicationContext ctx) {
20+
return args -> {
21+
22+
System.out.println("Let's inspect the beans provided by Spring Boot:");
23+
24+
String[] beanNames = ctx.getBeanDefinitionNames();
25+
Arrays.sort(beanNames);
26+
for (String beanName : beanNames) {
27+
System.out.println(beanName);
28+
}
29+
30+
};
31+
}
32+
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.example.springboot;
2+
3+
import org.springframework.web.bind.annotation.RestController;
4+
import org.springframework.web.bind.annotation.RequestMapping;
5+
6+
@RestController
7+
public class HelloController {
8+
9+
String my_sql_db = System.getenv("MY_MYSQL_DB");
10+
11+
@RequestMapping("/")
12+
public String index() {
13+
return my_sql_db;
14+
}
15+
16+
}

kustomize-app/base/configMap.yaml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
apiVersion: v1
2+
kind: ConfigMap
3+
metadata:
4+
name: the-map
5+
data:
6+
mysqlDB: "mysql.example.com:3306"
7+

kustomize-app/base/deployment.yaml

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: the-deployment
5+
labels:
6+
deployment: demo
7+
spec:
8+
replicas: 1
9+
template:
10+
metadata:
11+
labels:
12+
deployment: demo
13+
spec:
14+
containers:
15+
- name: the-container
16+
image: docker.io/kostiscodefresh/gitops-simple-app:v1.0
17+
ports:
18+
- containerPort: 8080
19+
imagePullPolicy: Always
20+
env:
21+
- name: MY_MYSQL_DB
22+
valueFrom:
23+
configMapKeyRef:
24+
name: the-map
25+
key: mysqlDB

kustomize-app/base/kustomization.yaml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
commonLabels:
2+
app: demo
3+
4+
resources:
5+
- deployment.yaml
6+
- service.yaml
7+
- configMap.yaml

kustomize-app/base/service.yaml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
name: demo
5+
labels:
6+
app: demo
7+
spec:
8+
ports:
9+
- port: 8080
10+
selector:
11+
app: demo
12+
type: ClusterIP

kustomize-app/overlays/.DS_Store

6 KB
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
apiVersion: v1
2+
kind: ConfigMap
3+
metadata:
4+
name: the-map
5+
data:
6+
mysqlDB: "prod-mysql.example.com:3306"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: the-deployment
5+
spec:
6+
replicas: 3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namePrefix: production-
2+
commonLabels:
3+
variant: production
4+
bases:
5+
- ../../base
6+
patchesStrategicMerge:
7+
- deployment.yaml
8+
- config-map.yaml
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
apiVersion: v1
2+
kind: ConfigMap
3+
metadata:
4+
name: the-map
5+
data:
6+
mysqlDB: "staging-mysql.example.com:3306"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namePrefix: staging-
2+
commonLabels:
3+
variant: staging
4+
bases:
5+
- ../../base
6+
patchesStrategicMerge:
7+
- config-map.yaml

kustomize-app/prod-codefresh.yml

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# More examples of Codefresh YAML can be found at
2+
# https://codefresh.io/docs/docs/yaml-examples/examples/
3+
4+
version: "1.0"
5+
# Stages can help you organize your steps in stages
6+
7+
stages:
8+
- clone
9+
- deploy
10+
11+
steps:
12+
clone:
13+
title: "Cloning repository"
14+
type: "git-clone"
15+
repo: "codefresh-contrib/gitops-certification-examples"
16+
revision: "main"
17+
stage: "clone"
18+
19+
deploy:
20+
title: Deploying to Staging using Kustomize...
21+
type: freestyle
22+
stage: deploy
23+
working_directory: ${{clone}}/kustomize-app/overlays/production
24+
arguments:
25+
image: docker.io/kostiscodefresh/gitops-simple-app:v1.0
26+
commands:
27+
- kubectl config use-context docker-desktop
28+
- kubectl apply -k overlays/production

kustomize-app/staging-codefresh.yml

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# More examples of Codefresh YAML can be found at
2+
# https://codefresh.io/docs/docs/yaml-examples/examples/
3+
4+
version: "1.0"
5+
# Stages can help you organize your steps in stages
6+
7+
stages:
8+
- clone
9+
- deploy
10+
11+
steps:
12+
clone:
13+
title: "Cloning repository"
14+
type: "git-clone"
15+
repo: "codefresh-contrib/gitops-certification-examples"
16+
revision: "main"
17+
stage: "clone"
18+
19+
deploy:
20+
title: Deploying to Staging using Kustomize...
21+
type: freestyle
22+
stage: deploy
23+
working_directory: ${{clone}}/kustomize-app/overlays/staging
24+
arguments:
25+
image: docker.io/kostiscodefresh/gitops-simple-app:v1.0
26+
commands:
27+
- kubectl config use-context docker-desktop
28+
- kubectl apply -k overlays/staging

pictures/argocd-deploy-staging-ui.png

169 KB
Loading

0 commit comments

Comments
 (0)