mirror of
https://github.com/clearlinux/dockerfiles.git
synced 2026-08-19 12:16:37 +00:00
Add "tomcat deploy with k8s"
This commit is contained in:
@@ -52,9 +52,44 @@ Docker Hub.
|
||||
docker run --rm -it --hostname my-tomcat --name some-tomcat -p 8080:8080 clearlinux/tomcat
|
||||
```
|
||||
|
||||
|
||||
<!-- Optional -->
|
||||
### Deploy with Kubernetes
|
||||
|
||||
This image can also be deployed on a Kubernetes cluster, such as [minikube](https://kubernetes.io/docs/setup/learning-environment/minikube/).The following example YAML files are provided in the repository as reference for Kubernetes deployment:
|
||||
|
||||
- [`tomcat-deployment.yaml`](https://github.com/clearlinux/dockerfiles/blob/master/tomcat/tomcat-deployment.yaml): example using default configuration to create a basic tomcat service.
|
||||
|
||||
- [`tomcat-deployment-index-custom.yaml`](https://github.com/clearlinux/dockerfiles/blob/master/tomcat/tomcat-deployment-index-custom.yaml): example using your own custom index html to create a tomcat service.
|
||||
|
||||
- [`tomcat-deployment-conf-custom.yaml`](https://github.com/clearlinux/dockerfiles/blob/master/tomcat/tomcat-deployment-conf-custom.yaml): example using your own custom configuration to create a tomcat service.
|
||||
|
||||
|
||||
|
||||
Steps to deploy tomcat on a Kubernetes cluster:
|
||||
|
||||
1. If you want to deploy `tomcat-deployment.yaml`
|
||||
|
||||
```
|
||||
kubectl create -f tomcat-deployment.yaml
|
||||
```
|
||||
|
||||
Or if you want to deploy `tomcat-deployment-index-custom.yaml`
|
||||
|
||||
```
|
||||
kubectl create -f tomcat-deployment-index-custom.yaml
|
||||
```
|
||||
|
||||
Or if you want to deploy `tomcat-deployment-conf-custom.yaml`
|
||||
|
||||
```
|
||||
kubectl create -f tomcat-deployment-conf-custom.yaml
|
||||
```
|
||||
|
||||
2. Navigate to [http://\<nodeIP\>:30001](http://\<nodeIP\>:30001) in your browser, where 30001 is the port number defined in your service.
|
||||
|
||||
|
||||
|
||||
<!-- Required -->
|
||||
## Build and modify:
|
||||
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: tomcat-conf
|
||||
data:
|
||||
server.xml: |
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Server port="8005" shutdown="SHUTDOWN">
|
||||
<Listener className="org.apache.catalina.startup.VersionLoggerListener" />
|
||||
<Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
|
||||
<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
|
||||
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
|
||||
<Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />
|
||||
|
||||
<GlobalNamingResources>
|
||||
<Resource name="UserDatabase" auth="Container"
|
||||
type="org.apache.catalina.UserDatabase"
|
||||
description="User database that can be updated and saved"
|
||||
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
|
||||
pathname="conf/tomcat-users.xml" />
|
||||
</GlobalNamingResources>
|
||||
|
||||
<Service name="Catalina">
|
||||
<Connector port="8080" protocol="HTTP/1.1"
|
||||
connectionTimeout="20000"
|
||||
redirectPort="8443" />
|
||||
|
||||
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
|
||||
<Engine name="Catalina" defaultHost="localhost">
|
||||
<Realm className="org.apache.catalina.realm.LockOutRealm">
|
||||
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
|
||||
resourceName="UserDatabase"/>
|
||||
</Realm>
|
||||
<Host name="localhost" appBase="webapps"
|
||||
unpackWARs="true" autoDeploy="true">
|
||||
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
|
||||
prefix="localhost_access_log" suffix=".txt"
|
||||
pattern="%h %l %u %t "%r" %s %b" />
|
||||
</Host>
|
||||
</Engine>
|
||||
</Service>
|
||||
</Server>
|
||||
|
||||
---
|
||||
apiVersion: extensions/v1beta1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: my-tomcat
|
||||
spec:
|
||||
replicas: 1
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: my-tomcat
|
||||
spec:
|
||||
containers:
|
||||
- name: my-tomcat
|
||||
image: docker.io/clearlinux/tomcat
|
||||
ports:
|
||||
- containerPort: 8080
|
||||
volumeMounts:
|
||||
- name: config-volume
|
||||
mountPath: /usr/share/apache-tomcat/conf/server.xml
|
||||
subPath: server.xml
|
||||
volumes:
|
||||
- name: config-volume
|
||||
configMap:
|
||||
name: tomcat-conf
|
||||
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: my-tomcat
|
||||
spec:
|
||||
type: NodePort
|
||||
ports:
|
||||
- port: 8080
|
||||
targetPort: 8080
|
||||
nodePort: 30001
|
||||
selector:
|
||||
app: my-tomcat
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: tomcat-conf
|
||||
data:
|
||||
index.jsp: |
|
||||
hello,tomcat!
|
||||
|
||||
---
|
||||
apiVersion: extensions/v1beta1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: my-tomcat
|
||||
spec:
|
||||
replicas: 1
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: my-tomcat
|
||||
spec:
|
||||
containers:
|
||||
- name: my-tomcat
|
||||
image: docker.io/clearlinux/tomcat
|
||||
ports:
|
||||
- containerPort: 8080
|
||||
volumeMounts:
|
||||
- name: config-volume
|
||||
mountPath: /usr/share/apache-tomcat/webapps/ROOT/index.jsp
|
||||
subPath: index.jsp
|
||||
volumes:
|
||||
- name: config-volume
|
||||
configMap:
|
||||
name: tomcat-conf
|
||||
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: my-tomcat
|
||||
spec:
|
||||
type: NodePort
|
||||
ports:
|
||||
- port: 8080
|
||||
targetPort: 8080
|
||||
nodePort: 30001
|
||||
selector:
|
||||
app: my-tomcat
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
apiVersion: extensions/v1beta1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: my-tomcat
|
||||
spec:
|
||||
replicas: 1
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: my-tomcat
|
||||
spec:
|
||||
containers:
|
||||
- name: my-tomcat
|
||||
image: docker.io/clearlinux/tomcat
|
||||
ports:
|
||||
- containerPort: 8080
|
||||
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: my-tomcat
|
||||
spec:
|
||||
type: NodePort
|
||||
ports:
|
||||
- port: 8080
|
||||
targetPort: 8080
|
||||
nodePort: 30001
|
||||
selector:
|
||||
app: my-tomcat
|
||||
Reference in New Issue
Block a user