<p>We are migrating the blog system that was previously deployed on EC2 to the AWS EKS cluster. On EC2 of the existing system, it operates in two containers, a web server (nginx) container and an AP server (django + gunicorn) container, and can be accessed normally from a browser. So, when I deployed it to the node (EC2) on AWS EKS in the same way, I could not access it from the browser and it was displayed as &quot;502 Bad Gateway&quot;. The message &quot;TIMEOUT (pid: 18294)&quot; is displayed. We are currently investigating the cause of this, but the current situation is that we do not know. If anyone has any idea, I would appreciate it if you could teach me.</p>
<p>gunicorn of log・status</p>
<pre><code>root@blogsystem-apserver01:/# systemctl status gunicorn
● gunicorn.service - gunicorn daemon
     Loaded: loaded (/etc/systemd/system/gunicorn.service; enabled; vendor preset: enabled)
     Active: active (running) since Sun 2021-05-09 08:57:19 UTC; 5 days ago
   Main PID: 18291 (gunicorn)
      Tasks: 4 (limit: 4636)
     Memory: 95.8M
     CGroup: /kubepods/besteffort/podd270872c-cc5b-4a3b-92ed-f463ee5f5d77/1eafc79ffd656ff1c1bc39175ee06c7a5ca8692715c5e2bfe2f979d8718411ba/system.slice/gunicorn.service
             ├─18291 /home/ubuntu/python3/bin/python /home/ubuntu/python3/bin/gunicorn --access-logfile - --workers 3 --bind unix:/home/ubuntu/socket/myproject.sock myproject.wsgi:a
pplication
             ├─18295 /home/ubuntu/python3/bin/python /home/ubuntu/python3/bin/gunicorn --access-logfile - --workers 3 --bind unix:/home/ubuntu/socket/myproject.sock myproject.wsgi:a
pplication
             ├─18299 /home/ubuntu/python3/bin/python /home/ubuntu/python3/bin/gunicorn --access-logfile - --workers 3 --bind unix:/home/ubuntu/socket/myproject.sock myproject.wsgi:a
pplication
             └─18300 /home/ubuntu/python3/bin/python /home/ubuntu/python3/bin/gunicorn --access-logfile - --workers 3 --bind unix:/home/ubuntu/socket/myproject.sock myproject.wsgi:a
pplication

May 09 08:57:20 blogsystem-apserver01 gunicorn[18291]: [2021-05-09 08:57:20 +0000] [18291] [INFO] Starting gunicorn 20.0.4
May 09 08:57:20 blogsystem-apserver01 gunicorn[18291]: [2021-05-09 08:57:20 +0000] [18291] [INFO] Listening at: unix:/home/ubuntu/socket/myproject.sock (18291)
May 09 08:57:20 blogsystem-apserver01 gunicorn[18291]: [2021-05-09 08:57:20 +0000] [18291] [INFO] Using worker: sync
May 09 08:57:20 blogsystem-apserver01 gunicorn[18293]: [2021-05-09 08:57:20 +0000] [18293] [INFO] Booting worker with pid: 18293
May 09 08:57:20 blogsystem-apserver01 gunicorn[18294]: [2021-05-09 08:57:20 +0000] [18294] [INFO] Booting worker with pid: 18294
May 09 08:57:20 blogsystem-apserver01 gunicorn[18295]: [2021-05-09 08:57:20 +0000] [18295] [INFO] Booting worker with pid: 18295
May 09 08:57:59 blogsystem-apserver01 gunicorn[18291]: [2021-05-09 08:57:59 +0000] [18291] [CRITICAL] WORKER TIMEOUT (pid:18293)
May 09 08:58:00 blogsystem-apserver01 gunicorn[18299]: [2021-05-09 08:58:00 +0000] [18299] [INFO] Booting worker with pid: 18299
May 09 08:58:01 blogsystem-apserver01 gunicorn[18291]: [2021-05-09 08:58:01 +0000] [18291] [CRITICAL] WORKER TIMEOUT (pid:18294)
May 09 08:58:02 blogsystem-apserver01 gunicorn[18300]: [2021-05-09 08:58:02 +0000] [18300] [INFO] Booting worker with pid: 18300
root@blogsystem-apserver01:/# 
</code></pre>
<p>Further investigation
I've researched various things, but I can't conclude, but it seems that there is a possibility that it can be solved by changing the &quot;sync&quot; worker of gunicorn to the &quot;givent&quot; worker.</p>
<p>reference:
<a href="https://github.com/benoitc/gunicorn/issues/1194" rel="nofollow noreferrer">https://github.com/benoitc/gunicorn/issues/1194</a></p>
<p>I tried to edit the gunicorn config file and change it to a &quot;givent&quot; worker as below, but when I restart gunicorn and look at the status, it says &quot;Runtime Error: gevent worker requires gevent 1.4 or higher&quot; And I can't start gunicorn. Then, I installed a version of gevent of 1.4 or higher with &quot;python3 -m pip install gevent&quot;, but again, &quot;RuntimeError: gevent worker requires gevent 1.4 or higher&quot; is displayed. I think that this matter may also be related to &quot;WORKER TIMEOUT&quot; of gunicorn mentioned above, so if you have any idea how to solve it, I would appreciate it if you could tell me.</p>
<p>・gunicorn configuration file</p>
<pre><code>(python3) ubuntu@blogsystem-apserver01:/etc/systemd/system$ more gunicorn.service 
[Unit]
Description=gunicorn daemon
After=network.target

[Service]
User=ubuntu
Group=www-data
WorkingDirectory=/home/ubuntu/myproject
ExecStart=/home/ubuntu/python3/bin/gunicorn --access-logfile - --workers 3 --worker-class gevent --bind unix:/home/ubuntu/socket/myproject.sock myproject.wsgi:application

[Install]
WantedBy=multi-user.target
(python3) ubuntu@blogsystem-apserver01:/etc/systemd/system$ 
</code></pre>
<p>・gunicorn status</p>
<pre><code>root@blogsystem-apserver01:/etc/systemd/system# systemctl status gunicorn
● gunicorn.service - gunicorn daemon
     Loaded: loaded (/etc/systemd/system/gunicorn.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Sat 2021-05-15 02:30:08 UTC; 1s ago
    Process: 19182 ExecStart=/home/ubuntu/python3/bin/gunicorn --access-logfile - --workers 3 --worker-class gevent --bind unix:/home/ubuntu/socket/myproject.sock myproject.wsgi:a
pplication (code=exited, status=1/FAILURE)
   Main PID: 19182 (code=exited, status=1/FAILURE)

May 15 02:30:08 blogsystem-apserver01 gunicorn[19182]:   File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 975, in _find_and_load_unlocked
May 15 02:30:08 blogsystem-apserver01 gunicorn[19182]:   File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 671, in _load_unlocked
May 15 02:30:08 blogsystem-apserver01 gunicorn[19182]:   File &quot;&lt;frozen importlib._bootstrap_external&gt;&quot;, line 783, in exec_module
May 15 02:30:08 blogsystem-apserver01 gunicorn[19182]:   File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 219, in _call_with_frames_removed
May 15 02:30:08 blogsystem-apserver01 gunicorn[19182]:   File &quot;/home/ubuntu/python3/lib/python3.8/site-packages/gunicorn/workers/ggevent.py&quot;, line 16, in &lt;module&gt;
May 15 02:30:08 blogsystem-apserver01 gunicorn[19182]:     raise RuntimeError(&quot;gevent worker requires gevent 1.4 or higher&quot;)
May 15 02:30:08 blogsystem-apserver01 gunicorn[19182]: RuntimeError: gevent worker requires gevent 1.4 or higher
May 15 02:30:08 blogsystem-apserver01 gunicorn[19182]: ]
May 15 02:30:08 blogsystem-apserver01 systemd[1]: gunicorn.service: Main process exited, code=exited, status=1/FAILURE
May 15 02:30:08 blogsystem-apserver01 systemd[1]: gunicorn.service: Failed with result 'exit-code'.
root@blogsystem-apserver01:/etc/systemd/system#
</code></pre>
<p>・gevent worker install</p>
<pre><code>root@blogsystem-apserver01:/etc/systemd/system# python3 -m pip install gevent 
Requirement already satisfied: gevent in /usr/local/lib/python3.8/dist-packages (1.4.0)
Requirement already satisfied: greenlet&gt;=0.4.14 in /usr/local/lib/python3.8/dist-packages (from gevent) (1.1.0)
WARNING: Running pip as root will break packages and permissions. You should install packages reliably by using venv: https://pip.pypa.io/warnings/venv
root@blogsystem-apserver01:/etc/systemd/system# 
</code></pre>
<p>・Gunicorn status after reboot after installing gevent worker</p>
<pre><code>root@blogsystem-apserver01:/etc/systemd/system# systemctl restart gunicorn
root@blogsystem-apserver01:/etc/systemd/system# 
root@blogsystem-apserver01:/etc/systemd/system# systemctl status gunicorn
● gunicorn.service - gunicorn daemon
     Loaded: loaded (/etc/systemd/system/gunicorn.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Sat 2021-05-15 03:08:42 UTC; 1s ago
    Process: 19196 ExecStart=/home/ubuntu/python3/bin/gunicorn --access-logfile - --workers 3 --worker-class gevent --bind unix:/home/ubuntu/socket/myproject.sock myproject.wsgi:a
pplication (code=exited, status=1/FAILURE)
   Main PID: 19196 (code=exited, status=1/FAILURE)

May 15 03:08:42 blogsystem-apserver01 gunicorn[19196]:   File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 975, in _find_and_load_unlocked
May 15 03:08:42 blogsystem-apserver01 gunicorn[19196]:   File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 671, in _load_unlocked
May 15 03:08:42 blogsystem-apserver01 gunicorn[19196]:   File &quot;&lt;frozen importlib._bootstrap_external&gt;&quot;, line 783, in exec_module
May 15 03:08:42 blogsystem-apserver01 gunicorn[19196]:   File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 219, in _call_with_frames_removed
May 15 03:08:42 blogsystem-apserver01 gunicorn[19196]:   File &quot;/home/ubuntu/python3/lib/python3.8/site-packages/gunicorn/workers/ggevent.py&quot;, line 16, in &lt;module&gt;
May 15 03:08:42 blogsystem-apserver01 gunicorn[19196]:     raise RuntimeError(&quot;gevent worker requires gevent 1.4 or higher&quot;)
May 15 03:08:42 blogsystem-apserver01 gunicorn[19196]: RuntimeError: gevent worker requires gevent 1.4 or higher
May 15 03:08:42 blogsystem-apserver01 gunicorn[19196]: ]
May 15 03:08:42 blogsystem-apserver01 systemd[1]: gunicorn.service: Main process exited, code=exited, status=1/FAILURE
May 15 03:08:42 blogsystem-apserver01 systemd[1]: gunicorn.service: Failed with result 'exit-code'.
root@blogsystem-apserver01:/etc/systemd/system# 
</code></pre>

kan
<p>I solved it myself. I'm sorry for making a noise.</p>
<p>The cause was that the VPC of RDS originally used in the existing environment (AWS) and the VPC of the newly constructed AWS EKS cluster were different. As a result, the AP server was unable to connect to RDS and gunicorn was timing out. When I installed ESK and RDS in the same VPC, it became accessible from a browser and the problem was solved.</p>
