We discovered that this happened due to the token size which increased as we progressed with the development of functionality, which in turn resulted in the generation of a larger token based on additional authorization information.
The question still remains, why are we getting a 502 Bad Gateway. The HTTP 502 occurred due to the size of the header and on response to the HTTP request coming in, the kubernetes proxy rejected the request due to its header size.
So, we had to add the following line to the ingress of our application's docker descriptor:
- ingress.kubernetes.io/proxy-buffer-size: 16k