<p>I have ingress and service with LB. When traffic coming from outside it hits ingress first and then does it goes to pods directly using ingress LB or it goes to service and get the pod ip via selector and then goes to pods? If it's first way, what is the use of services? And which kind, services or ingress uses readinessProbe in the deployment?</p>

<p>All the setup is in GCP</p>

<p>I am new to K8 networks.</p>

Sid
<p>A service type <code>LoadBalancer</code> is a external source provided by your cloud and are NOT in Kubernetes cluster. They can work forwarding the request to your pods using node selector, but you can't for example make path rules or redirect, rewrites because this is provided by an Ingress.</p>

<blockquote>
  <p><strong>Service</strong> is an abstraction which defines a logical set of Pods and a policy by which to access them (sometimes this pattern is called a micro-service). The set of Pods targeted by a Service is usually determined by a selector (see below for why you might want a Service without a selector).</p>
</blockquote>

<pre><code>        Internet
            |
     [ LoadBalancer ]
       --|-----|--
       [ Services ]
       --|      |--
    [ Pod1 ]  [ Pod2 ]
</code></pre>

<p>When you use <strong>Ingress</strong>, is a <em>component</em> controller by a ingress controller that is basically a pod configured to handle the rules you defined. 
To use ingress you need to configure a service for your path, and then this service will reach the pods with configures selectors. You can configure some rules based on path, hostname and them redirect for the service you want. Like this:</p>

<pre><code>        Internet
            |
       [ Ingress ]
       --|-----|--
       [ Services ]
       --|      |--
    [ Pod1 ]  [ Pod2 ]
</code></pre>

<blockquote>
  <p><strong>Ingress</strong> exposes HTTP and HTTPS routes from outside the cluster to services within the cluster. Traffic routing is controlled by rules defined on the Ingress resource.</p>
</blockquote>

<p><a href="https://medium.com/google-cloud/kubernetes-nodeport-vs-loadbalancer-vs-ingress-when-should-i-use-what-922f010849e0" rel="nofollow noreferrer">This article</a> has a good explanation between all ways to expose your service.</p>

<p>The <a href="https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/#define-readiness-probes" rel="nofollow noreferrer"><strong>readnessProbe</strong></a> is configured in your pod/deployment specs, and <strong>kubelet</strong> is responsible to evaluate your container healthy.</p>

<blockquote>
  <p>The kubelet uses readiness probes to know when a Container is ready to start accepting traffic. A Pod is considered ready when all of its Containers are ready. One use of this signal is to control which Pods are used as backends for Services. When a Pod is not ready, it is removed from Service load balancers.</p>
</blockquote>

<p><a href="https://kubernetes.io/docs/concepts/overview/components/#kube-proxy" rel="nofollow noreferrer">kube-proxy</a> is the responsible to foward the request for the pods. </p>

<p>For example, if you have 2 pods in different nodes, kube-proxy will handle the firewall rules (iptables) and distribute the traffic between your nodes. Each node in your cluster has a kube-proxy running.</p>

<p>kube-proxy can be configured in 3 ways: <a href="https://kubernetes.io/docs/concepts/services-networking/service/#proxy-mode-userspace" rel="nofollow noreferrer">userspace mode</a>, <a href="https://kubernetes.io/docs/concepts/services-networking/service/#proxy-mode-iptables" rel="nofollow noreferrer">iptables mode</a> and <a href="https://kubernetes.io/docs/concepts/services-networking/service/#proxy-mode-ipvs" rel="nofollow noreferrer">ipvs mode</a>.</p>

<blockquote>
  <p>If kube-proxy is running in iptables mode and the first Pod that’s selected does not respond, the connection fails. This is different from userspace mode: in that scenario, kube-proxy would detect that the connection to the first Pod had failed and would automatically retry with a different backend Pod.</p>
</blockquote>

<p><strong>References:</strong></p>

<p><a href="https://kubernetes.io/docs/concepts/services-networking/service/" rel="nofollow noreferrer">https://kubernetes.io/docs/concepts/services-networking/service/</a></p>

<p><a href="https://kubernetes.io/docs/concepts/services-networking/ingress/" rel="nofollow noreferrer">https://kubernetes.io/docs/concepts/services-networking/ingress/</a></p>
