<p>I am working on my Django project and I am trying to deploy it on Kubernetes cluster ( Google Cloud Provider ). I've managed to create all the files I need for configuring the cluster:</p>

<ul>
<li>Django App Deployment + Service .yml files</li>
<li>Postgres DB Deployment + Service + PersistentVolumeClaim ( which dynamicly creates PersistentVolume object and uses PD storage on
cloud nodes by default )+ Secret .yml files</li>
<li>Docker File + Docker Compose ( I dont have much experience with docker so there might be something wrong with them, maybe that is the
issue but I cannot figure it out )</li>
</ul>

<p>For some reason when i try to apply them my PODs, specifically Django Application PODs, are Crashing in an infinite loop. Also my Postgres Pod is not crashing but it is not running eather.</p>

<p>Can anyone help me figure out what am I doing wrong? Here is my github repo: <a href="https://github.com/StefanCepa/agent-technologies-bachelor" rel="nofollow noreferrer">https://github.com/…/mast…/agents/config/kubernetes/postgres</a></p>

<p>My best guess is that I did not set <code>DATABASES</code> configuration in <code>settings.py</code> file correct, and that my Django Application cannot find DATABASE HOST specified in <code>settings.py</code>. If anyone has any suggestions please leave a comment.</p>

<p>Here is a picture of my Kubernetes Pod list:</p>

<p><a href="https://i.stack.imgur.com/88FTY.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/88FTY.png" alt="enter image description here"></a>
Here is a picture where I've described 1st Pod object:</p>

<p><a href="https://i.stack.imgur.com/ZT2EE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ZT2EE.png" alt="enter image description here"></a>
And here is a picture of one of my nodes described:</p>

<p><a href="https://i.stack.imgur.com/jFE4q.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jFE4q.png" alt="enter image description here"></a></p>

<p><strong>* UPDATE *</strong></p>

<p>Here is what my ERROR message looks like when i try to run <code>python src/manage.py runserver</code>:</p>

<pre><code>(web_development) cepa995@cepa995-VirtualBox:~/Agentske_Tehnologije/agents$ python src/manage.py runserver
/home/cepa995/anaconda3/envs/web_development/lib/python3.6/site-packages/psycopg2/__init__.py:144: UserWarning: The psycopg2 wheel package will be renamed from release 2.8; in order to keep installing from binary please use "pip install psycopg2-binary" instead. For details see: &lt;http://initd.org/psycopg/docs/install.html#binary-install-from-pypi&gt;.
  """)
/home/cepa995/anaconda3/envs/web_development/lib/python3.6/site-packages/psycopg2/__init__.py:144: UserWarning: The psycopg2 wheel package will be renamed from release 2.8; in order to keep installing from binary please use "pip install psycopg2-binary" instead. For details see: &lt;http://initd.org/psycopg/docs/install.html#binary-install-from-pypi&gt;.
  """)
Performing system checks...

System check identified no issues (0 silenced).
Unhandled exception in thread started by &lt;function check_errors.&lt;locals&gt;.wrapper at 0x7f6b37e9a9d8&gt;
Traceback (most recent call last):
  File "/home/cepa995/anaconda3/envs/web_development/lib/python3.6/site-packages/django/db/backends/base/base.py", line 216, in ensure_connection
    self.connect()
  File "/home/cepa995/anaconda3/envs/web_development/lib/python3.6/site-packages/django/db/backends/base/base.py", line 194, in connect
    self.connection = self.get_new_connection(conn_params)
  File "/home/cepa995/anaconda3/envs/web_development/lib/python3.6/site-packages/django/db/backends/postgresql/base.py", line 168, in get_new_connection
    connection = Database.connect(**conn_params)
  File "/home/cepa995/anaconda3/envs/web_development/lib/python3.6/site-packages/psycopg2/__init__.py", line 130, in connect
    conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
psycopg2.OperationalError: could not translate host name "postgres-service" to address: Name or service not known


The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/cepa995/anaconda3/envs/web_development/lib/python3.6/site-packages/django/utils/autoreload.py", line 225, in wrapper
    fn(*args, **kwargs)
  File "/home/cepa995/anaconda3/envs/web_development/lib/python3.6/site-packages/django/core/management/commands/runserver.py", line 124, in inner_run
    self.check_migrations()
  File "/home/cepa995/anaconda3/envs/web_development/lib/python3.6/site-packages/django/core/management/base.py", line 427, in check_migrations
    executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS])
  File "/home/cepa995/anaconda3/envs/web_development/lib/python3.6/site-packages/django/db/migrations/executor.py", line 18, in __init__
    self.loader = MigrationLoader(self.connection)
  File "/home/cepa995/anaconda3/envs/web_development/lib/python3.6/site-packages/django/db/migrations/loader.py", line 49, in __init__
    self.build_graph()
  File "/home/cepa995/anaconda3/envs/web_development/lib/python3.6/site-packages/django/db/migrations/loader.py", line 206, in build_graph
    self.applied_migrations = recorder.applied_migrations()
  File "/home/cepa995/anaconda3/envs/web_development/lib/python3.6/site-packages/django/db/migrations/recorder.py", line 61, in applied_migrations
    if self.has_table():
  File "/home/cepa995/anaconda3/envs/web_development/lib/python3.6/site-packages/django/db/migrations/recorder.py", line 44, in has_table
    return self.Migration._meta.db_table in self.connection.introspection.table_names(self.connection.cursor())
  File "/home/cepa995/anaconda3/envs/web_development/lib/python3.6/site-packages/django/db/backends/base/base.py", line 255, in cursor
    return self._cursor()
  File "/home/cepa995/anaconda3/envs/web_development/lib/python3.6/site-packages/django/db/backends/base/base.py", line 232, in _cursor
    self.ensure_connection()
  File "/home/cepa995/anaconda3/envs/web_development/lib/python3.6/site-packages/django/db/backends/base/base.py", line 216, in ensure_connection
    self.connect()
  File "/home/cepa995/anaconda3/envs/web_development/lib/python3.6/site-packages/django/db/utils.py", line 89, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/home/cepa995/anaconda3/envs/web_development/lib/python3.6/site-packages/django/db/backends/base/base.py", line 216, in ensure_connection
    self.connect()
  File "/home/cepa995/anaconda3/envs/web_development/lib/python3.6/site-packages/django/db/backends/base/base.py", line 194, in connect
    self.connection = self.get_new_connection(conn_params)
  File "/home/cepa995/anaconda3/envs/web_development/lib/python3.6/site-packages/django/db/backends/postgresql/base.py", line 168, in get_new_connection
    connection = Database.connect(**conn_params)
  File "/home/cepa995/anaconda3/envs/web_development/lib/python3.6/site-packages/psycopg2/__init__.py", line 130, in connect
    conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
django.db.utils.OperationalError: could not translate host name "postgres-service" to address: Name or service not known
</code></pre>

Stefan Radonjic
<p>Your application cannot connect to the database, because your Postgres server cannot start (you have 0/1 pods in <code>Ready</code> state).</p>

<p>You did not publish its Pod events, but I guess the main reason is its volume. </p>

<p>In your Postgres specs, I see you set the volume type to
<code>ReadWriteMany</code>, but Google Cloud does not provide volumes with that type (<a href="https://kubernetes.io/docs/concepts/storage/persistent-volumes/#persistent-volumes" rel="nofollow noreferrer">documentation</a>, path "Access Modes") and, actually, I don't see the reason why you need it. Change the type to <code>ReadWriteOnce</code> and redeploy the database, it should help.</p>

<p>P.S. To get a log of application in a cluster, you can call <code>kubectl logs $podname</code>, it’s much more helpful 
P.P.S. When you publish text information, use a text format, please. </p>
