Fix markdown (#1395)

* Fix markdown

* Fix all indentations in numbered lists

* add additional "space" indentation for #1202
This commit is contained in:
Adriano Cunha 2019-05-30 11:00:36 -07:00 committed by Knative Prow Robot
parent eaa9bbf59b
commit 65adb947ae
1 changed files with 139 additions and 140 deletions

View File

@ -6,11 +6,9 @@ Follow the steps below to create the sample code and then deploy the app to your
cluster. You can also download a working copy of the sample, by running the cluster. You can also download a working copy of the sample, by running the
following commands: following commands:
```shell ```shell
git clone -b "release-0.6" https://github.com/knative/docs knative-docs cd git clone -b "release-0.6" https://github.com/knative/docs knative-docs cd
knative-docs/serving/samples/hello-world/helloworld-java-spring knative-docs/serving/samples/hello-world/helloworld-java-spring
```` ````
## Before you begin ## Before you begin
@ -26,116 +24,116 @@ and a Docker Hub account configured (we'll use it for a container registry).
## Recreating the sample code ## Recreating the sample code
1. From the console, create a new empty web project using the curl and unzip 1. From the console, create a new empty web project using the curl and unzip
commands: commands:
```shell ```shell
curl https://start.spring.io/starter.zip \ curl https://start.spring.io/starter.zip \
-d dependencies=web \ -d dependencies=web \
-d name=helloworld \ -d name=helloworld \
-d artifactId=helloworld \ -d artifactId=helloworld \
-o helloworld.zip -o helloworld.zip
unzip helloworld.zip unzip helloworld.zip
``` ```
If you don't have curl installed, you can accomplish the same by visiting the If you don't have curl installed, you can accomplish the same by visiting the
[Spring Initializr](https://start.spring.io/) page. Specify Artifact as [Spring Initializr](https://start.spring.io/) page. Specify Artifact as
`helloworld` and add the `Web` dependency. Then click `Generate Project`, `helloworld` and add the `Web` dependency. Then click `Generate Project`,
download and unzip the sample archive. download and unzip the sample archive.
1. Update the `SpringBootApplication` class in 1. Update the `SpringBootApplication` class in
`src/main/java/com/example/helloworld/HelloworldApplication.java` by adding a `src/main/java/com/example/helloworld/HelloworldApplication.java` by adding a
`@RestController` to handle the "/" mapping and also add a `@Value` field to `@RestController` to handle the "/" mapping and also add a `@Value` field to
provide the TARGET environment variable: provide the TARGET environment variable:
```java ```java
package com.example.helloworld; package com.example.helloworld;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
@SpringBootApplication @SpringBootApplication
public class HelloworldApplication { public class HelloworldApplication {
@Value("${TARGET:World}") @Value("${TARGET:World}")
String target; String target;
@RestController @RestController
class HelloworldController { class HelloworldController {
@GetMapping("/") @GetMapping("/")
String hello() { String hello() {
return "Hello " + target + "!"; return "Hello " + target + "!";
} }
}
public static void main(String[] args) {
SpringApplication.run(HelloworldApplication.class, args);
}
} }
```
public static void main(String[] args) {
SpringApplication.run(HelloworldApplication.class, args);
}
}
```
1. Run the application locally: 1. Run the application locally:
```shell ```shell
./mvnw package && java -jar target/helloworld-0.0.1-SNAPSHOT.jar ./mvnw package && java -jar target/helloworld-0.0.1-SNAPSHOT.jar
``` ```
Go to `http://localhost:8080/` to see your `Hello World!` message. Go to `http://localhost:8080/` to see your `Hello World!` message.
1. In your project directory, create a file named `Dockerfile` and copy the code 1. In your project directory, create a file named `Dockerfile` and copy the code
block below into it. For detailed instructions on dockerizing a Spring Boot block below into it. For detailed instructions on dockerizing a Spring Boot
app, see app, see
[Spring Boot with Docker](https://spring.io/guides/gs/spring-boot-docker/). [Spring Boot with Docker](https://spring.io/guides/gs/spring-boot-docker/).
For additional information on multi-stage docker builds for Java see For additional information on multi-stage docker builds for Java see
[Creating Smaller Java Image using Docker Multi-stage Build](http://blog.arungupta.me/smaller-java-image-docker-multi-stage-build/). [Creating Smaller Java Image using Docker Multi-stage Build](http://blog.arungupta.me/smaller-java-image-docker-multi-stage-build/).
```docker ```docker
# Use the official maven/Java 8 image to create a build artifact. # Use the official maven/Java 8 image to create a build artifact.
# https://hub.docker.com/_/maven # https://hub.docker.com/_/maven
FROM maven:3.5-jdk-8-alpine as builder FROM maven:3.5-jdk-8-alpine as builder
# Copy local code to the container image. # Copy local code to the container image.
WORKDIR /app WORKDIR /app
COPY pom.xml . COPY pom.xml .
COPY src ./src COPY src ./src
# Build a release artifact. # Build a release artifact.
RUN mvn package -DskipTests RUN mvn package -DskipTests
# Use AdoptOpenJDK for base image. # Use AdoptOpenJDK for base image.
# It's important to use OpenJDK 8u191 or above that has container support enabled. # It's important to use OpenJDK 8u191 or above that has container support enabled.
# https://hub.docker.com/r/adoptopenjdk/openjdk8 # https://hub.docker.com/r/adoptopenjdk/openjdk8
# https://docs.docker.com/develop/develop-images/multistage-build/#use-multi-stage-builds # https://docs.docker.com/develop/develop-images/multistage-build/#use-multi-stage-builds
FROM adoptopenjdk/openjdk8:jdk8u202-b08-alpine-slim FROM adoptopenjdk/openjdk8:jdk8u202-b08-alpine-slim
# Copy the jar to the production image from the builder stage. # Copy the jar to the production image from the builder stage.
COPY --from=builder /app/target/helloworld-*.jar /helloworld.jar COPY --from=builder /app/target/helloworld-*.jar /helloworld.jar
# Run the web service on container startup. # Run the web service on container startup.
CMD ["java","-Djava.security.egd=file:/dev/./urandom","-Dserver.port=${PORT}","-jar","/helloworld.jar"] CMD ["java","-Djava.security.egd=file:/dev/./urandom","-Dserver.port=${PORT}","-jar","/helloworld.jar"]
``` ```
1. Create a new file, `service.yaml` and copy the following service definition 1. Create a new file, `service.yaml` and copy the following service definition
into the file. Make sure to replace `{username}` with your Docker Hub into the file. Make sure to replace `{username}` with your Docker Hub
username. username.
```yaml ```yaml
apiVersion: serving.knative.dev/v1alpha1 apiVersion: serving.knative.dev/v1alpha1
kind: Service kind: Service
metadata: metadata:
name: helloworld-java-spring name: helloworld-java-spring
namespace: default namespace: default
spec: spec:
template: template:
spec: spec:
containers: containers:
- image: docker.io/{username}/helloworld-java-spring - image: docker.io/{username}/helloworld-java-spring
env: env:
- name: TARGET - name: TARGET
value: "Spring Boot Sample v1" value: "Spring Boot Sample v1"
``` ```
## Building and deploying the sample ## Building and deploying the sample
@ -143,83 +141,84 @@ Once you have recreated the sample code files (or used the files in the sample
folder) you're ready to build and deploy the sample app. folder) you're ready to build and deploy the sample app.
1. Use Docker to build the sample code into a container. To build and push with 1. Use Docker to build the sample code into a container. To build and push with
Docker Hub, run these commands replacing `{username}` with your Docker Hub Docker Hub, run these commands replacing `{username}` with your Docker Hub
username: username:
```shell ```shell
# Build the container on your local machine # Build the container on your local machine
docker build -t {username}/helloworld-java-spring . docker build -t {username}/helloworld-java-spring .
# Push the container to docker registry # Push the container to docker registry
docker push {username}/helloworld-java-spring docker push {username}/helloworld-java-spring
``` ```
1. After the build has completed and the container is pushed to docker hub, you 1. After the build has completed and the container is pushed to docker hub, you
can deploy the app into your cluster. Ensure that the container image value can deploy the app into your cluster. Ensure that the container image value
in `service.yaml` matches the container you built in the previous step. Apply in `service.yaml` matches the container you built in the previous step. Apply
the configuration using `kubectl`: the configuration using `kubectl`:
```shell ```shell
kubectl apply --filename service.yaml kubectl apply --filename service.yaml
``` ```
1. Now that your service is created, Knative will perform the following steps: 1. Now that your service is created, Knative will perform the following steps:
- Create a new immutable revision for this version of the app. - Create a new immutable revision for this version of the app.
- Network programming to create a route, ingress, service, and load balancer - Network programming to create a route, ingress, service, and load balancer
for your app. for your app.
- Automatically scale your pods up and down (including to zero active pods). - Automatically scale your pods up and down (including to zero active pods).
1. To find the IP address for your service, use. If your cluster is new, it may 1. To find the IP address for your service, use. If your cluster is new, it may
take sometime for the service to get asssigned an external IP address. take sometime for the service to get asssigned an external IP address.
```shell ```shell
# In Knative 0.2.x and prior versions, the `knative-ingressgateway` service was used instead of `istio-ingressgateway`. # In Knative 0.2.x and prior versions, the `knative-ingressgateway` service was used instead of `istio-ingressgateway`.
INGRESSGATEWAY=knative-ingressgateway INGRESSGATEWAY=knative-ingressgateway
# The use of `knative-ingressgateway` is deprecated in Knative v0.3.x. # The use of `knative-ingressgateway` is deprecated in Knative v0.3.x.
# Use `istio-ingressgateway` instead, since `knative-ingressgateway` # Use `istio-ingressgateway` instead, since `knative-ingressgateway`
# will be removed in Knative v0.4. # will be removed in Knative v0.4.
if kubectl get configmap config-istio -n knative-serving &> /dev/null; then if kubectl get configmap config-istio -n knative-serving &> /dev/null; then
INGRESSGATEWAY=istio-ingressgateway INGRESSGATEWAY=istio-ingressgateway
fi fi
kubectl get svc $INGRESSGATEWAY --namespace istio-system kubectl get svc $INGRESSGATEWAY --namespace istio-system
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
xxxxxxx-ingressgateway LoadBalancer 10.23.247.74 35.203.155.229 80:32380/TCP,443:32390/TCP,32400:32400/TCP 2d xxxxxxx-ingressgateway LoadBalancer 10.23.247.74 35.203.155.229 80:32380/TCP,443:32390/TCP,32400:32400/TCP 2d
# Now you can assign the external IP address to the env variable. # Now you can assign the external IP address to the env variable.
export IP_ADDRESS=<EXTERNAL-IP column from the command above> export IP_ADDRESS=<EXTERNAL-IP column from the command above>
# Or just execute: # Or just execute:
export IP_ADDRESS=$(kubectl get svc $INGRESSGATEWAY \
--namespace istio-system \ export IP_ADDRESS=$(kubectl get svc $INGRESSGATEWAY \
--output jsonpath="{.status.loadBalancer.ingress[*].ip}") --namespace istio-system \
``` --output jsonpath="{.status.loadBalancer.ingress[*].ip}")
```
1. To find the URL for your service, use 1. To find the URL for your service, use
```shell ```shell
kubectl get ksvc helloworld-java-spring \ kubectl get ksvc helloworld-java-spring \
--output=custom-columns=NAME:.metadata.name,DOMAIN:.status.domain --output=custom-columns=NAME:.metadata.name,DOMAIN:.status.domain
NAME DOMAIN NAME DOMAIN
helloworld-java-spring helloworld-java-spring.default.example.com helloworld-java-spring helloworld-java-spring.default.example.com
# Or simply: # Or simply:
export DOMAIN_NAME=$(kubectl get ksvc helloworld-java-spring \ export DOMAIN_NAME=$(kubectl get ksvc helloworld-java-spring \
--output jsonpath={.status.domain} --output jsonpath={.status.domain}
``` ```
1. Now you can make a request to your app to see the result. Presuming, the IP 1. Now you can make a request to your app to see the result. Presuming, the IP
address you got in the step above is in the `${IP_ADDRESS}` env variable: address you got in the step above is in the `${IP_ADDRESS}` env variable:
```shell ```shell
curl -H "Host: ${DOMAIN_NAME}" http://${IP_ADDRESS} curl -H "Host: ${DOMAIN_NAME}" http://${IP_ADDRESS}
Hello Spring Boot Sample v1! Hello Spring Boot Sample v1!
``` ```
## Removing the sample app deployment ## Removing the sample app deployment