From 9dfeb35c97e157d91eec55613382cd0b7a644163 Mon Sep 17 00:00:00 2001 From: timlackhan <727781157@qq.com> Date: Tue, 17 Sep 2019 11:41:25 +0800 Subject: [PATCH] Add "tomcat deploy with k8s" --- tomcat/README.md | 35 +++++++++ tomcat/tomcat-deployment-conf-custom.yaml | 83 ++++++++++++++++++++++ tomcat/tomcat-deployment-index-custom.yaml | 48 +++++++++++++ tomcat/tomcat-deployment.yaml | 30 ++++++++ 4 files changed, 196 insertions(+) create mode 100644 tomcat/tomcat-deployment-conf-custom.yaml create mode 100644 tomcat/tomcat-deployment-index-custom.yaml create mode 100644 tomcat/tomcat-deployment.yaml diff --git a/tomcat/README.md b/tomcat/README.md index 61b585c..1dc00a8 100644 --- a/tomcat/README.md +++ b/tomcat/README.md @@ -52,9 +52,44 @@ Docker Hub. docker run --rm -it --hostname my-tomcat --name some-tomcat -p 8080:8080 clearlinux/tomcat ``` + ### 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://\:30001](http://\:30001) in your browser, where 30001 is the port number defined in your service. + + + ## Build and modify: diff --git a/tomcat/tomcat-deployment-conf-custom.yaml b/tomcat/tomcat-deployment-conf-custom.yaml new file mode 100644 index 0000000..5968ce4 --- /dev/null +++ b/tomcat/tomcat-deployment-conf-custom.yaml @@ -0,0 +1,83 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: tomcat-conf +data: + server.xml: | + + + + + + + + + + + + + + + + + + + + + + + + + + + +--- +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 + diff --git a/tomcat/tomcat-deployment-index-custom.yaml b/tomcat/tomcat-deployment-index-custom.yaml new file mode 100644 index 0000000..7a610e3 --- /dev/null +++ b/tomcat/tomcat-deployment-index-custom.yaml @@ -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 + diff --git a/tomcat/tomcat-deployment.yaml b/tomcat/tomcat-deployment.yaml new file mode 100644 index 0000000..8d7f963 --- /dev/null +++ b/tomcat/tomcat-deployment.yaml @@ -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