<p>I have next situation and I am not sure if it is possible to achieve it using kubernetes only.</p>
<p>There are two pods, one with live service is available on e.g. givemedata.example.com, temporary one on givemedata2.example.com. Temporary one is without any dependency and there just to allow some long term jobs to continue run while real one is down for maintenance.</p>
<p>Cluster is on GKE.</p>
<p>I need to setup failover so that if live one is down for maintenance, failover should redirect calls to temporary one.</p>
<p>Main reason is to use only one endpoint, e.g. givemedata.example.com.</p>
<p>My question is if this is possible and how to do it?</p>

EnterSB
<p>You can install <a href="https://kubernetes.github.io/ingress-nginx/" rel="nofollow noreferrer">NGINX  ingress controller</a>. Add
<code>nginx.ingress.kubernetes.io/server-snippet:</code> annotation to ingress configuration file and add block of code which will check if domain is available, if not it will redirect traffic to different one.</p>
<p>Thanks to this annotation it is possible to add custom configuration in the server configuration block.</p>
<p>Read more: <a href="https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/annotations/#server-snippet" rel="nofollow noreferrer">server snippet</a>.</p>
<p>Remember to add this server to <code>nginx.conf</code> file in <strong>/etc/nginx</strong> directory.
Here is example cofiguration:</p>
<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
 name: my-ingress
 namespace: ingress-nginx
 annotations:
   kubernetes.io/ingress.class: nginx
   nginx.ingress.kubernetes.io/add-base-url : &quot;true&quot;
   nginx.ingress.kubernetes.io/configuration-snippet: |
      set $agentflag 0;  
      if ($http_user_agent ~* &quot;(Mobile)&quot; ){  
      set $agentflag 1;  
      }  
      if ( $agentflag = 1 ) {  
      return 301 https://givemedata2.example.com;  
      }
spec:
 rules:
 - host: givemedata.example.com
   http:
     paths:
     - path: /
       backend:
         serviceName: service-name
         servicePort: service-port
</code></pre>
