Please don't mark this as duplicate.I have made some changes this time.Believe me, I have tried other answers and they don't seem to solve my issue.I am unable to link tomcat container with my MySQL database container in kubernetes.
Built my tomcat image using this dockerfile
FROM picoded/tomcat7
COPY data-core-0.0.1-SNAPSHOT.war /usr/local/tomcat/webapps/data-core-0.0.1-SNAPSHOT.war
mysql-service.yaml
apiVersion: v1
kind: Service
metadata:
name: mysql
spec:
ports:
- port: 3306
selector:
app: mysql
mysql-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: mysql
spec:
selector:
matchLabels:
app: mysql
strategy:
type: Recreate
template:
metadata:
labels:
app: mysql
spec:
containers:
- image: mysql:5.6
name: mysql
imagePullPolicy: "IfNotPresent"
env:
- name: MYSQL_ROOT_PASSWORD
value: root
- name: MYSQL_DATABASE
value: data-core
ports:
- containerPort: 3306
name: mysql
volumeMounts:
- name: mysql-persistent-storage
mountPath: /docker-entrypoint-initdb.d //my sql init script will
get copied from hostpath
of persistant volume.
volumes:
- name: mysql-persistent-storage
persistentVolumeClaim:
claimName: mysql-initdb-pv-claim
Tomcat-service.yaml
apiVersion: v1
kind: Service
metadata:
name: tomcat
labels:
app: tomcat
spec:
type: NodePort
ports:
- name: myport
port: 8080
targetPort: 8080
nodePort: 30000
selector:
app: tomcat
tier: frontend
Tomcat-Deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: tomcat
labels:
app: tomcat
spec:
selector:
matchLabels:
app: tomcat
tier: frontend
strategy:
type: Recreate
template:
metadata:
labels:
app: tomcat
tier: frontend
spec:
containers:
- image: suji165475/vignesh:tomcatserver //this is the tomcat image
built using dockerfile with
war file(spring boot app)
copied to webapps folder
name: tomcat
env:
- name: DB_PORT_3306_TCP_ADDR
value: mysql #service name of mysql
- name: DB_ENV_MYSQL_DATABASE
value: data-core
- name: DB_ENV_MYSQL_ROOT_PASSWORD
value: root
ports:
- containerPort: 8080
name: myport
volumeMounts:
- name: tomcat-persistent-storage
mountPath: /var/data
volumes:
- name: tomcat-persistent-storage
persistentVolumeClaim:
claimName: tomcat-pv-claim
I have specified all the environment variables including the MySQL service name in the Tomcat deployment needed for connecting them.Also made sure to create persistent volumes and claims for both the containers.Yet my war file still wont start in tomcat's manager app.
Are my yaml files correct or is there still some changes to be made??
NOTE: I am running on a server using putty terminal.
URL used to access my app in browser-
206.189.22.155:30000/data-core-0.0.1-SNAPSHOT