text stringlengths 0 59.1k |
|---|
``` |
And the contents of `mv.sh` is: |
```sh |
cp /sample.war /app |
tail -f /dev/null |
``` |
#### Explanation |
1. 'war' container only contains the `war` file of your app |
2. 'war' container's CMD tries to copy `sample.war` to the `emptyDir` volume path |
3. The last line of `tail -f` is just used to hold the container, as Replication Controller does not support one-off task |
4. 'tomcat' container will load the `sample.war` from volume path |
What's more, if you don't want to enclose a build-in `mv.sh` script in the `war` container, you can use Pod's `command` to do the copy work, here's a example [javaweb-2.yaml](javaweb-2.yaml): |
<!-- BEGIN MUNGE: javaweb-2.yaml --> |
```yaml |
apiVersion: v1 |
kind: Pod |
metadata: |
name: javaweb-2 |
spec: |
initContainers: |
- image: resouer/sample:v2 |
name: war |
command: |
- "cp" |
- "/sample.war" |
- "/app" |
volumeMounts: |
- mountPath: /app |
name: app-volume |
containers: |
- image: resouer/mytomcat:7.0 |
name: tomcat |
command: ["sh","-c","/root/apache-tomcat-7.0.42-v2/bin/start.sh"] |
volumeMounts: |
- mountPath: /root/apache-tomcat-7.0.42-v2/webapps |
name: app-volume |
ports: |
- containerPort: 8080 |
hostPort: 8001 |
volumes: |
- name: app-volume |
emptyDir: {} |
``` |
<!-- END MUNGE: EXAMPLE --> |
And the `resouer/sample:v2` Dockerfile is quite simple: |
``` |
FROM busybox:latest |
ADD sample.war sample.war |
CMD "tail" "-f" "/dev/null" |
``` |
#### Explanation |
1. 'war' container only contains the `war` file of your app |
2. 'war' container's CMD uses `tail -f` to hold the container, nothing more |
3. The `command` will do `cp` after the `war` container is started |
4. Again 'tomcat' container will load the `sample.war` from volume path |
Done! Now your `war` container contains nothing except `sample.war`, clean enough. |
### Test It Out |
Create the Java web pod: |
```console |
$ kubectl create -f examples/javaweb-tomcat-sidecar/javaweb-2.yaml |
``` |
Check status of the pod: |
```console |
$ kubectl get -w po |
NAME READY STATUS RESTARTS AGE |
javaweb-2 2/2 Running 0 7s |
``` |
Wait for the status to `0/1` and `Running`. Then you can visit "Hello, World" page on `http://localhost:8001/sample/index.html` |
You can also test `javaweb.yaml` in the same way. |
### Delete Resources |
All resources created in this application can be deleted: |
```console |
$ kubectl delete -f examples/javaweb-tomcat-sidecar/javaweb-2.yaml |
``` |
<|endoftext|> |
# source: k8s_examples/_archived/javaweb-tomcat-sidecar/javaweb-2.yaml type: yaml |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.