Skip to content

Commit cd10198

Browse files
author
Ryan Baxter
committed
Use includes instead
1 parent 1d8779f commit cd10198

File tree

1 file changed

+3
-77
lines changed

1 file changed

+3
-77
lines changed

README.adoc

Lines changed: 3 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -296,9 +296,7 @@ Create a new file called `application.properties` in the `k8s` directory. In tha
296296
.application.properties
297297
[source,properties]
298298
----
299-
server.shutdown=graceful
300-
301-
management.endpoints.web.exposure.include=*
299+
include::app/k8s/application.properties[]
302300
----
303301

304302
Alternatively you can do this in one easy step from the command line by running the following command.
@@ -348,50 +346,7 @@ To do this, we need to modify our deployment YAML to first create the volume and
348346
.k8s/deployment.yaml
349347
[source,yaml]
350348
----
351-
apiVersion: apps/v1
352-
kind: Deployment
353-
metadata:
354-
creationTimestamp: null
355-
labels:
356-
app: gs-spring-boot-k8s
357-
name: gs-spring-boot-k8s
358-
spec:
359-
replicas: 1
360-
selector:
361-
matchLabels:
362-
app: gs-spring-boot-k8s
363-
strategy: {}
364-
template:
365-
metadata:
366-
creationTimestamp: null
367-
labels:
368-
app: gs-spring-boot-k8s
369-
spec:
370-
containers:
371-
- image: spring-k8s/gs-spring-boot-k8s:snapshot
372-
name: gs-spring-boot-k8s
373-
resources: {}
374-
livenessProbe:
375-
httpGet:
376-
path: /actuator/health/liveness
377-
port: 8080
378-
readinessProbe:
379-
httpGet:
380-
path: /actuator/health/readiness
381-
port: 8080
382-
lifecycle:
383-
preStop:
384-
exec:
385-
command: ["sh", "-c", "sleep 10"]
386-
volumeMounts:
387-
- name: config-volume
388-
mountPath: /workspace/config
389-
volumes:
390-
- name: config-volume
391-
configMap:
392-
name: gs-spring-boot-k8s
393-
status: {}
394-
349+
include::app/k8s/deployment.yaml[]
395350
----
396351

397352
With all of our best practices implemented, we can apply the new deployment to Kubernetes. This deploys another Pod and
@@ -491,38 +446,9 @@ all the pods.
491446

492447
In your application, open `DemoApplication.java` in `src/main/java/com/example/demo`. Modify the code as follows:
493448

494-
.DemoApplication.java
495449
[source,java]
496450
----
497-
package com.example.demo;
498-
499-
import reactor.core.publisher.Mono;
500-
501-
import org.springframework.boot.SpringApplication;
502-
import org.springframework.boot.autoconfigure.SpringBootApplication;
503-
import org.springframework.web.bind.annotation.GetMapping;
504-
import org.springframework.web.bind.annotation.RestController;
505-
import org.springframework.web.reactive.function.client.WebClient;
506-
507-
@SpringBootApplication
508-
@RestController
509-
public class DemoApplication {
510-
511-
private WebClient webClient = WebClient.builder().build();
512-
513-
public static void main(String[] args) {
514-
SpringApplication.run(DemoApplication.class, args);
515-
}
516-
517-
@GetMapping
518-
public Mono<String> index() {
519-
return webClient.get().uri("http://k8s-workshop-name-service").exchange().flatMap(clientResponse -> {
520-
String host = clientResponse.headers().asHttpHeaders().get("k8s-host").get(0);
521-
return clientResponse.bodyToMono(String.class).flatMap(name -> Mono.just("Hello " + name + " from " + host));
522-
});
523-
}
524-
}
525-
451+
include::app/src/main/java/com/example/demo/DemoApplication.java[]
526452
----
527453

528454
Notice the URL in the `WebClient` request is `k8s-workshop-name-service`. That is the ID of our service in Kubernetes.

0 commit comments

Comments
 (0)