Skip to content

Commit fe25b18

Browse files
committed
Squashing commits
adding a Java EE sample, fixing kubernetes#11477 adding location to the source adding partial review comments from kubernetes#12110 adding syncer macros and fixing links
1 parent 5f36c07 commit fe25b18

File tree

4 files changed

+229
-0
lines changed

4 files changed

+229
-0
lines changed

examples/javaee/README.md

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
<!-- BEGIN MUNGE: UNVERSIONED_WARNING -->
2+
3+
<!-- BEGIN STRIP_FOR_RELEASE -->
4+
5+
<img src="http://kubernetes.io/img/warning.png" alt="WARNING"
6+
width="25" height="25">
7+
<img src="http://kubernetes.io/img/warning.png" alt="WARNING"
8+
width="25" height="25">
9+
<img src="http://kubernetes.io/img/warning.png" alt="WARNING"
10+
width="25" height="25">
11+
<img src="http://kubernetes.io/img/warning.png" alt="WARNING"
12+
width="25" height="25">
13+
<img src="http://kubernetes.io/img/warning.png" alt="WARNING"
14+
width="25" height="25">
15+
16+
<h2>PLEASE NOTE: This document applies to the HEAD of the source tree</h2>
17+
18+
If you are using a released version of Kubernetes, you should
19+
refer to the docs that go with that version.
20+
21+
<strong>
22+
The latest 1.0.x release of this document can be found
23+
[here](http://releases.k8s.io/release-1.0/examples/javaee/README.md).
24+
25+
Documentation for other releases can be found at
26+
[releases.k8s.io](http://releases.k8s.io).
27+
</strong>
28+
--
29+
30+
<!-- END STRIP_FOR_RELEASE -->
31+
32+
<!-- END MUNGE: UNVERSIONED_WARNING -->
33+
34+
## Java EE Application using WildFly and MySQL
35+
36+
The following document describes the deployment of a Java EE application using [WildFly](http://wildfly.org) application server and MySQL database server on Kubernetes. The sample application source code is at: https://github.com/javaee-samples/javaee7-simple-sample.
37+
38+
### Prerequisites
39+
40+
https://github.com/GoogleCloudPlatform/kubernetes/blob/master/docs/user-guide/prereqs.md
41+
42+
### Start MySQL Pod
43+
44+
In Kubernetes a [_Pod_](../../docs/user-guide/pods.md) is the smallest deployable unit that can be created, scheduled, and managed. Its a collocated group of containers that share an IP and storage volume.
45+
46+
Here is the config for MySQL pod: [mysql-pod.yaml](mysql-pod.yaml)
47+
48+
<!-- BEGIN MUNGE: mysql-pod.yaml -->
49+
<!-- END MUNGE: EXAMPLE -->
50+
51+
Create the MySQL pod:
52+
53+
```sh
54+
kubectl create -f examples/javaee/mysql-pod.yaml
55+
```
56+
57+
Check status of the pod:
58+
59+
```sh
60+
kubectl get -w po
61+
NAME READY STATUS RESTARTS AGE
62+
mysql-pod 0/1 Pending 0 4s
63+
NAME READY STATUS RESTARTS AGE
64+
mysql-pod 0/1 Running 0 44s
65+
mysql-pod 1/1 Running 0 44s
66+
```
67+
68+
Wait for the status to `1/1` and `Running`.
69+
70+
### Start MySQL Service
71+
72+
We are creating a [_Service_](../../docs/user-guide/services.md) to expose the TCP port of the MySQL server. A Service distributes traffic across a set of Pods. The order of Service and the targeted Pods does not matter. However Service needs to be started before any other Pods consuming the Service are started.
73+
74+
In this application, we will use a Kubernetes Service to provide a discoverable endpoints for the MySQL endpoint in the cluster. MySQL service target pods with the labels `name: mysql-pod` and `context: docker-k8s-lab`.
75+
76+
Here is definition of the MySQL service: [mysql-service.yaml](mysql-service.yaml)
77+
78+
<!-- BEGIN MUNGE: mysql-service.yaml -->
79+
<!-- END MUNGE: EXAMPLE -->
80+
81+
Create this service:
82+
83+
```sh
84+
kubectl create -f examples/javaee/mysql-service.yaml
85+
```
86+
87+
Get status of the service:
88+
89+
```sh
90+
kubectl get -w se
91+
NAME LABELS SELECTOR IP(S) PORT(S)
92+
kubernetes component=apiserver,provider=kubernetes <none> 10.247.0.1 443/TCP
93+
mysql-service context=docker-k8s-lab,name=mysql-pod context=docker-k8s-lab,name=mysql-pod 10.247.63.43 3306/TCP
94+
```
95+
96+
If multiple services are running, then it can be narrowed by specifying labels:
97+
98+
```sh
99+
kubectl get -w po -l context=docker-k8s-lab,name=mysql-pod
100+
NAME READY STATUS RESTARTS AGE
101+
mysql-pod 1/1 Running 0 4m
102+
```
103+
104+
This is also the selector label used by service to target pods.
105+
106+
When a Service is run on a node, the kubelet adds a set of environment variables for each active Service. It supports both Docker links compatible variables and simpler `{SVCNAME}_SERVICE_HOST` and `{SVCNAME}_SERVICE_PORT` variables, where the Service name is upper-cased and dashes are converted to underscores.
107+
108+
Our service name is ``mysql-service'' and so ``MYSQL_SERVICE_SERVICE_HOST'' and ``MYSQL_SERVICE_SERVICE_PORT'' variables are available to other pods. This host and port variables are then used to create the JDBC resource in WildFly.
109+
110+
### Start WildFly Replication Controller
111+
112+
WildFly is a lightweight Java EE 7 compliant application server. It is wrapped in a Replication Controller and used as the Java EE runtime.
113+
114+
In Kubernetes a [_Replication Controller_](../../docs/user-guide/replication-controller.md) is responsible for replicating sets of identical pods. Like a _Service_ it has a selector query which identifies the members of it's set. Unlike a service it also has a desired number of replicas, and it will create or delete pods to ensure that the number of pods matches up with it's desired state.
115+
116+
Here is definition of the MySQL service: [wildfly-rc.yaml](wildfly-rc.yaml).
117+
118+
<!-- BEGIN MUNGE: wildfly-rc.yaml -->
119+
<!-- END MUNGE: EXAMPLE -->
120+
121+
Create this controller:
122+
123+
```sh
124+
kubectl create -f examples/javaee/wildfly-rc.yaml
125+
```
126+
127+
Check status of the pod inside replication controller:
128+
129+
```sh
130+
kubectl get po
131+
NAME READY STATUS RESTARTS AGE
132+
mysql-pod 1/1 Running 0 1h
133+
wildfly-rc-w2kk5 1/1 Running 0 6m
134+
```
135+
136+
### Access the application
137+
138+
Get IP address of the pod:
139+
140+
```sh
141+
kubectl get -o template po wildfly-rc-w2kk5 --template={{.status.podIP}}
142+
10.246.1.23
143+
```
144+
145+
Log in to minion and access the application:
146+
147+
```sh
148+
vagrant ssh minion-1
149+
Last login: Thu Jul 16 00:24:36 2015 from 10.0.2.2
150+
[vagrant@kubernetes-minion-1 ~]$ curl http://10.246.1.23:8080/employees/resources/employees/
151+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><collection><employee><id>1</id><name>Penny</name></employee><employee><id>2</id><name>Sheldon</name></employee><employee><id>3</id><name>Amy</name></employee><employee><id>4</id><name>Leonard</name></employee><employee><id>5</id><name>Bernadette</name></employee><employee><id>6</id><name>Raj</name></employee><employee><id>7</id><name>Howard</name></employee><employee><id>8</id><name>Priya</name></employee></collection>
152+
```
153+
154+
### Delete resources
155+
156+
All resources created in this application can be deleted:
157+
158+
```sh
159+
kubectl delete -f examples/javaee/mysql-pod.yaml
160+
kubectl delete -f examples/javaee/mysql-service.yaml
161+
kubectl delete -f examples/javaee/wildfly-rc.yaml
162+
```
163+
164+
165+
<!-- BEGIN MUNGE: GENERATED_ANALYTICS -->
166+
[![Analytics](https://kubernetes-site.appspot.com/UA-36037335-10/GitHub/examples/javaee/README.md?pixel)]()
167+
<!-- END MUNGE: GENERATED_ANALYTICS -->

examples/javaee/mysql-pod.yaml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
apiVersion: v1
2+
kind: Pod
3+
metadata:
4+
name: mysql-pod
5+
labels:
6+
name: mysql-pod
7+
context: docker-k8s-lab
8+
spec:
9+
containers:
10+
-
11+
name: mysql
12+
image: mysql:latest
13+
env:
14+
-
15+
name: "MYSQL_USER"
16+
value: "mysql"
17+
-
18+
name: "MYSQL_PASSWORD"
19+
value: "mysql"
20+
-
21+
name: "MYSQL_DATABASE"
22+
value: "sample"
23+
-
24+
name: "MYSQL_ROOT_PASSWORD"
25+
value: "supersecret"
26+
ports:
27+
-
28+
containerPort: 3306

examples/javaee/mysql-service.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
name: mysql-service
5+
labels:
6+
name: mysql-pod
7+
context: docker-k8s-lab
8+
spec:
9+
ports:
10+
# the port that this service should serve on
11+
- port: 3306
12+
# label keys and values that must match in order to receive traffic for this service
13+
selector:
14+
name: mysql-pod
15+
context: docker-k8s-lab

examples/javaee/wildfly-rc.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
apiVersion: v1
2+
kind: ReplicationController
3+
metadata:
4+
name: wildfly-rc
5+
labels:
6+
name: wildfly
7+
context: docker-k8s-lab
8+
spec:
9+
replicas: 1
10+
template:
11+
metadata:
12+
labels:
13+
name: wildfly
14+
spec:
15+
containers:
16+
- name: wildfly-rc-pod
17+
image: arungupta/wildfly-mysql-javaee7:k8s
18+
ports:
19+
- containerPort: 8080

0 commit comments

Comments
 (0)