Some times we have to enter specific hosts file entries to the container running inside the POD of a kubernetes deployment during the initial deployment stage itself.
If these entries are not in place, the application env variables mentioned in the yaml file , as hostnames , will not resolve to the IP address and the application will not start properly.
So to make sure the /etc/hosts file entries are already there after the spin up of the POD you can add the below entries in your yaml file.
cat > api-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
spec:
template:
metadata:
spec:
volumes:
containers:
- image: registryserver.jinojoseph.com:5000/jinojosephimage:v1.13
lifecycle:
postStart:
exec:
command: ["/bin/sh", "-c", "echo 10.0.1.10 namenode.jinojoseph.com >> /etc/hosts && echo 10.0.1.8 dn1.jinojoseph.com >> /etc/hosts && echo 10.0.1.4 dn2.jinojoseph.com >> /etc/hosts && echo 10.0.1.9 haproxy.jinojoseph.com >> /etc/hosts && echo 10.0.1.12 k8snn1.jinojoseph.com >> /etc/hosts && echo 10.0.1.13 haproxy1.jinojoseph.com >> /etc/hosts && echo 10.0.1.14 master.jinojoseph.com >> /etc/hosts && echo 10.0.1.23 worker1.jinojoseph.com >> /etc/hosts && echo 10.0.1.6 worker2.jinojoseph.com >> /etc/hosts"]
imagePullPolicy: IfNotPresent
name: jinojoseph-api
env:
- name: spring.data.cassandra.contact-points
value: "master.jinojoseph.com,worker1.jinojoseph.com,worker2.jinojoseph.com"
- name: hive.url
value: "jdbc:hive2://master.jinojoseph.com:2181,worker1.jinojoseph.com:2181,worker2.jinojoseph.com:2181/;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=hiveserver2"
If these entries are not in place, the application env variables mentioned in the yaml file , as hostnames , will not resolve to the IP address and the application will not start properly.
So to make sure the /etc/hosts file entries are already there after the spin up of the POD you can add the below entries in your yaml file.
cat > api-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
spec:
template:
metadata:
spec:
volumes:
containers:
- image: registryserver.jinojoseph.com:5000/jinojosephimage:v1.13
lifecycle:
postStart:
exec:
command: ["/bin/sh", "-c", "echo 10.0.1.10 namenode.jinojoseph.com >> /etc/hosts && echo 10.0.1.8 dn1.jinojoseph.com >> /etc/hosts && echo 10.0.1.4 dn2.jinojoseph.com >> /etc/hosts && echo 10.0.1.9 haproxy.jinojoseph.com >> /etc/hosts && echo 10.0.1.12 k8snn1.jinojoseph.com >> /etc/hosts && echo 10.0.1.13 haproxy1.jinojoseph.com >> /etc/hosts && echo 10.0.1.14 master.jinojoseph.com >> /etc/hosts && echo 10.0.1.23 worker1.jinojoseph.com >> /etc/hosts && echo 10.0.1.6 worker2.jinojoseph.com >> /etc/hosts"]
imagePullPolicy: IfNotPresent
name: jinojoseph-api
env:
- name: spring.data.cassandra.contact-points
value: "master.jinojoseph.com,worker1.jinojoseph.com,worker2.jinojoseph.com"
- name: hive.url
value: "jdbc:hive2://master.jinojoseph.com:2181,worker1.jinojoseph.com:2181,worker2.jinojoseph.com:2181/;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=hiveserver2"
Comments