My docker-compose file consisting of tomcat7 server and mysql database
version: '3'
services:
mysql:
image: suji165475/vignesh:latest
ports:
- "3066:3066"
tomcat:
image: suji165475/vignesh:tomcatserver
container_name: tomcat7hope
ports:
- "8080:8080"
I built the images using docker files
FROM mysql
ENV MYSQL_ROOT_PASSWORD=root
ADD init.sql /docker-entrypoint-initdb.d
FROM picoded/tomcat7
COPY data-core-0.0.1-SNAPSHOT.war /usr/local/tomcat/webapps/data-core-0.0.1-SNAPSHOT.war
how to run this on kubernetes clusture?? I already tried kompose convert and my war file wont start in tomcats application manager.But the war file starts succesfully using docker-compose up.
Why am I facing this issue only in kubernetes and not when directly running docker-compose up.Please help me by letting me know what changes I should make to the kubernetes yaml files.
mysql-deployment.yaml
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
annotations:
kompose.cmd: kompose convert
kompose.version: 1.18.0 (06a2e56)
creationTimestamp: null
labels:
io.kompose.service: mysql
name: mysql
spec:
replicas: 1
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
io.kompose.service: mysql
spec:
containers:
- image: suji165475/vignesh:latest
name: mysql
ports:
- containerPort: 3066
resources: {}
restartPolicy: Always
status: {}
tomcat-deployment.yaml
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
annotations:
kompose.cmd: kompose convert
kompose.version: 1.18.0 (06a2e56)
creationTimestamp: null
labels:
io.kompose.service: tomcat
name: tomcat
spec:
replicas: 1
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
io.kompose.service: tomcat
spec:
containers:
- image: suji165475/vignesh:tomcatserver
name: tomcat7hope
ports:
- containerPort: 8080
resources: {}
restartPolicy: Always
status: {}
mysql-service.yaml
apiVersion: v1
kind: Service
metadata:
annotations:
kompose.cmd: kompose convert
kompose.version: 1.18.0 (06a2e56)
creationTimestamp: null
labels:
io.kompose.service: mysql
name: mysql
spec:
ports:
- name: "3066"
port: 3066
targetPort: 3066
selector:
io.kompose.service: mysql
status:
loadBalancer: {}
tomcat-service.yaml
apiVersion: v1
kind: Service
metadata:
annotations:
kompose.cmd: kompose convert
kompose.version: 1.18.0 (06a2e56)
creationTimestamp: null
labels:
io.kompose.service: tomcat
name: tomcat
spec:
ports:
- name: "8080"
port: 8080
targetPort: 8080
selector:
io.kompose.service: tomcat
status:
loadBalancer: {}
Let me make it clear, you can't "run docker-compose" on Kubernetes. If you wanted to do that, you should not be using Kubernetes.
With that said, using kompose
is not such a great idea. Docker compose yaml files are all different and kompose
simply makes a guess as to what the associated Kubernetes manifests would look like. If your application is very simple and you are lucky, kompose
might give you your manifests ready to be deployed, but that is not usually the case.
There could be a few reasons why this is not working for you:
tomcat
application is not correctly referencing your mysql
servicemysql
deployment is missing some variables or mounted volumes/filesYour tomcat
app can refer to your mysql
db through mysql:3066
and you might need to add some environment variables in your tomcat
deployment such as db name, db username and db password for authentication. Here are your edited tomcat
manifests:
deployment.yaml
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: tomcat
namespace: default
labels:
app: tomcat
spec:
replicas: 1
selector:
matchLabels:
app: tomcat
template:
metadata:
labels:
app: tomcat
spec:
containers:
- image: suji165475/vignesh:tomcatserver
name: tomcat7hope
ports:
- containerPort: 8080
service.yaml
apiVersion: v1
kind: Service
metadata:
name: tomcat
namespace: default
labels:
app: tomcat
spec:
ports:
- name: "8080"
port: 8080
targetPort: 8080
selector:
app: tomcat
Your mysql
deployment might require a PersistentVolumeClaim
or emptyDir
in order to keep your data. Take a look at attached volumes and confirm that you are not missing any volume mounts or environment variables that are needed. Here are your edited mysql
manifests:
deployment.yaml
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: mysql
namespace: default
labels:
app: mysql
spec:
replicas: 1
selector:
matchLabels:
app: mysql
template:
metadata:
labels:
app: mysql
spec:
containers:
- image: suji165475/vignesh:latest
name: mysql
ports:
- containerPort: 3066
env:
- name: MYSQL_ROOT_PASSWORD
value: root
service.yaml
apiVersion: v1
kind: Service
metadata:
name: mysql
namespace: default
labels:
app: mysql
spec:
ports:
- name: "3066"
port: 3066
targetPort: 3066
selector:
app: mysql