Skip to content

Commit 3a933a1

Browse files
committed
Initial commit
0 parents  commit 3a933a1

17 files changed

+1635
-0
lines changed

.gitignore

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
HELP.md
2+
target/
3+
!.mvn/wrapper/maven-wrapper.jar
4+
!**/src/main/**
5+
!**/src/test/**
6+
7+
### STS ###
8+
.apt_generated
9+
.classpath
10+
.factorypath
11+
.project
12+
.settings
13+
.springBeans
14+
.sts4-cache
15+
16+
### IntelliJ IDEA ###
17+
.idea
18+
*.iws
19+
*.iml
20+
*.ipr
21+
22+
### NetBeans ###
23+
/nbproject/private/
24+
/nbbuild/
25+
/dist/
26+
/nbdist/
27+
/.nb-gradle/
28+
build/
29+
30+
### VS Code ###
31+
.vscode/

README.md

+1,300
Large diffs are not rendered by default.
179 KB
Loading
562 KB
Loading

k8s/deployment.yaml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
creationTimestamp: null
5+
labels:
6+
app: k8s-example
7+
name: k8s-example
8+
spec:
9+
replicas: 1
10+
selector:
11+
matchLabels:
12+
app: k8s-example
13+
strategy: {}
14+
template:
15+
metadata:
16+
creationTimestamp: null
17+
labels:
18+
app: k8s-example
19+
spec:
20+
containers:
21+
- image: registry.hub.docker.com/aimeizi/k8s-example:latest
22+
name: k8s-example
23+
resources: {}
24+
status: {}

k8s/service.yaml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
creationTimestamp: null
5+
labels:
6+
app: k8s-example
7+
name: k8s-example
8+
spec:
9+
ports:
10+
- name: 80-8080
11+
port: 80
12+
protocol: TCP
13+
targetPort: 8080
14+
selector:
15+
app: k8s-example
16+
type: LoadBalancer # LoadBalancer 不需要kubectl port-forward 直接用映射出来的 IP 和端口访问
17+
status:
18+
loadBalancer: {}

k8s/service.yaml.bak

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
creationTimestamp: null
5+
labels:
6+
app: k8s-example
7+
name: k8s-example
8+
spec:
9+
ports:
10+
- name: 80-8080
11+
port: 80
12+
protocol: TCP
13+
targetPort: 8080
14+
selector:
15+
app: k8s-example
16+
type: ClusterIP # ClusterIP 需要 kubectl port-forward
17+
status:
18+
loadBalancer: {}

kustomize/base/deployment.yaml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
creationTimestamp: null
5+
labels:
6+
app: k8s-example
7+
name: k8s-example
8+
spec:
9+
replicas: 1
10+
selector:
11+
matchLabels:
12+
app: k8s-example
13+
strategy: {}
14+
template:
15+
metadata:
16+
creationTimestamp: null
17+
labels:
18+
app: k8s-example
19+
spec:
20+
containers:
21+
- image: registry.hub.docker.com/aimeizi/k8s-example:latest
22+
name: k8s-example
23+
resources: {}
24+
status: {}

kustomize/base/kustomization.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
apiVersion: kustomize.config.k8s.io/v1beta1
2+
kind: Kustomization
3+
4+
resources:
5+
- service.yaml
6+
- deployment.yaml

kustomize/base/service.yaml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
creationTimestamp: null
5+
labels:
6+
app: k8s-example
7+
name: k8s-example
8+
spec:
9+
ports:
10+
- name: 80-8080
11+
port: 80
12+
protocol: TCP
13+
targetPort: 8080
14+
selector:
15+
app: k8s-example
16+
type: LoadBalancer # LoadBalancer 不需要kubectl port-forward 直接用映射出来的 IP 和端口访问
17+
status:
18+
loadBalancer: {}

kustomize/qa/kustomization.yaml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
apiVersion: kustomize.config.k8s.io/v1beta1
2+
kind: Kustomization
3+
4+
resources:
5+
- ../base
6+
7+
patchesStrategicMerge:
8+
- update-replicas.yaml

kustomize/qa/update-replicas.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: k8s-example
5+
spec:
6+
replicas: 2

pom.xml

+125
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
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.3.0.BUILD-SNAPSHOT</version>
9+
<relativePath/> <!-- lookup parent from repository -->
10+
</parent>
11+
<groupId>net.ameizi</groupId>
12+
<artifactId>k8s-example</artifactId>
13+
<version>1.0.0</version>
14+
<name>k8s-example</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-actuator</artifactId>
25+
</dependency>
26+
<dependency>
27+
<groupId>org.springframework.boot</groupId>
28+
<artifactId>spring-boot-starter-web</artifactId>
29+
</dependency>
30+
31+
<dependency>
32+
<groupId>org.springframework.boot</groupId>
33+
<artifactId>spring-boot-devtools</artifactId>
34+
<scope>runtime</scope>
35+
<optional>true</optional>
36+
</dependency>
37+
<dependency>
38+
<groupId>org.springframework.boot</groupId>
39+
<artifactId>spring-boot-starter-test</artifactId>
40+
<scope>test</scope>
41+
<exclusions>
42+
<exclusion>
43+
<groupId>org.junit.vintage</groupId>
44+
<artifactId>junit-vintage-engine</artifactId>
45+
</exclusion>
46+
</exclusions>
47+
</dependency>
48+
</dependencies>
49+
50+
<build>
51+
<plugins>
52+
<plugin>
53+
<groupId>org.springframework.boot</groupId>
54+
<artifactId>spring-boot-maven-plugin</artifactId>
55+
<configuration>
56+
<image>
57+
<name>k8s-example:latest</name>
58+
</image>
59+
</configuration>
60+
</plugin>
61+
<plugin>
62+
<groupId>com.google.cloud.tools</groupId>
63+
<artifactId>jib-maven-plugin</artifactId>
64+
<version>2.2.0</version>
65+
<executions>
66+
<execution>
67+
<phase>package</phase>
68+
<goals>
69+
<goal>build</goal>
70+
</goals>
71+
</execution>
72+
</executions>
73+
<configuration>
74+
<from>
75+
<image>openjdk:8-jdk-alpine</image>
76+
</from>
77+
<to>
78+
<!-- 坑!!!这里切记一定要设置 docker registry的完整地址,否则会被坑死,构建的时候会报授权错误,原因在于执行 mvn package 命令后会打包构建镜像并进行推送,因此要设置镜像仓库的地址,并且记得在命令行进行镜像仓库登录(docker login) -->
79+
<!-- 此处构建不依赖docker daemon进程。说人话就是不需要启动docker服务 -->
80+
<image>registry.hub.docker.com/aimeizi/k8s-example:latest</image>
81+
</to>
82+
<container>
83+
<mainClass>net.ameizi.k8s.example.K8sExampleApplication</mainClass>
84+
<ports>
85+
<port>8080</port>
86+
</ports>
87+
</container>
88+
</configuration>
89+
</plugin>
90+
</plugins>
91+
</build>
92+
93+
<repositories>
94+
<repository>
95+
<id>spring-milestones</id>
96+
<name>Spring Milestones</name>
97+
<url>https://repo.spring.io/milestone</url>
98+
</repository>
99+
<repository>
100+
<id>spring-snapshots</id>
101+
<name>Spring Snapshots</name>
102+
<url>https://repo.spring.io/snapshot</url>
103+
<snapshots>
104+
<enabled>true</enabled>
105+
</snapshots>
106+
</repository>
107+
</repositories>
108+
109+
<pluginRepositories>
110+
<pluginRepository>
111+
<id>spring-milestones</id>
112+
<name>Spring Milestones</name>
113+
<url>https://repo.spring.io/milestone</url>
114+
</pluginRepository>
115+
<pluginRepository>
116+
<id>spring-snapshots</id>
117+
<name>Spring Snapshots</name>
118+
<url>https://repo.spring.io/snapshot</url>
119+
<snapshots>
120+
<enabled>true</enabled>
121+
</snapshots>
122+
</pluginRepository>
123+
</pluginRepositories>
124+
125+
</project>

skaffold.yaml

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
apiVersion: skaffold/v2beta3
2+
kind: Config
3+
metadata:
4+
name: k-s-example
5+
build:
6+
artifacts:
7+
- image: registry.hub.docker.com/aimeizi/k8s-example
8+
jib:
9+
project: net.ameizi:k8s-example
10+
deploy:
11+
# kubectl:
12+
# manifests:
13+
# - k8s/deployment.yaml
14+
# - k8s/service.yaml
15+
kustomize:
16+
paths: ["kustomize/base"]
17+
profiles:
18+
- name: qa
19+
deploy:
20+
kustomize:
21+
paths: ["kustomize/qa"]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package net.ameizi.k8s.example;
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+
@RestController
9+
@SpringBootApplication
10+
public class K8sExampleApplication {
11+
12+
public static void main(String[] args) {
13+
SpringApplication.run(K8sExampleApplication.class, args);
14+
}
15+
16+
@GetMapping("/hello")
17+
public String hello() {
18+
return "hello,Skaffold!";
19+
}
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
management.endpoint.shutdown.enabled=true
2+
management.endpoints.web.exposure.include=*
3+
management.endpoints.web.exposure.exclude=env
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package net.ameizi.k8s.example;
2+
3+
import org.junit.jupiter.api.Test;
4+
import org.springframework.boot.test.context.SpringBootTest;
5+
6+
@SpringBootTest
7+
class K8sExampleApplicationTests {
8+
9+
@Test
10+
void contextLoads() {
11+
}
12+
13+
}

0 commit comments

Comments
 (0)