<p>Readiness Probe keeps the application in at a non-ready state. While being in this state the application cannot connect to any kubernetes service.</p>

<p>I'm using Ubuntu 18 for both master and nodes for my kubernetes cluster. (The problem still appeared when I used only master in the cluster, so I don't think this is a master node kind of problem).</p>

<p>I set up my kubernetes cluster with an Spring application, which uses hazelcast in order to manage cache. So, while using readiness probe, the application can't access a kubernetes service I created in order to connect the applications via hazelcast using the <a href="https://github.com/hazelcast/hazelcast-kubernetes" rel="nofollow noreferrer">hazelcast-kubernetes</a> plugin.</p>

<p>When I take out the readiness-probe, the application connects as soon as it can to the service creating hazelcast clusters successfully and everything works properly.</p>

<p>The readiness probe will connect to a rest api which its only response is a 200 code. However, while the application is going up, in the middle of the process it will start the hazelcast cluster, and as such, it will try to connect to the kubernetes hazelcast service which connects the app's cache with other pods, while the readiness probe hasn't been cleared and the pod is in a non-ready state due to the probe. This is when the application will not be able to connect to the kubernetes service and it will either fail or get stuck as a consequence of the configuration I add.</p>

<p>service.yaml:</p>

<pre><code>apiVersion: v1
kind: Service
metadata:
  name: my-app-cluster-hazelcast
spec:
  selector:
    app: my-app
  ports:
  - name: hazelcast
    port: 5701
</code></pre>

<p>deployment.yaml:</p>

<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-app-deployment
  labels:
    app: my-app-deployment
spec:
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxUnavailable: 1
      maxSurge: 2
  replicas: 2
  selector:
    matchLabels:
      app: my-app
  template:
    metadata:
      labels:
        app: my-app
    spec:
      terminationGracePeriodSeconds: 180
      containers:
      - name: my-app
        image: my-repo:5000/my-app-container
        imagePullPolicy: Always
        ports:
        - containerPort: 5701
        - containerPort: 9080
        readinessProbe:
          httpGet:
            path: /app/api/excluded/sample
            port: 9080
          initialDelaySeconds: 120
          periodSeconds: 15
        securityContext:
          capabilities:
            add:
              - SYS_ADMIN
        env:
          - name: container
            value: docker
</code></pre>

<p>hazelcast.xml:</p>

<pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;

&lt;hazelcast
        xsi:schemaLocation="http://www.hazelcast.com/schema/config http://www.hazelcast.com/schema/config/hazelcast-config-3.11.xsd"
        xmlns="http://www.hazelcast.com/schema/config"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;

    &lt;properties&gt;
        &lt;property name="hazelcast.jmx"&gt;false&lt;/property&gt;
        &lt;property name="hazelcast.logging.type"&gt;slf4j&lt;/property&gt;
    &lt;/properties&gt;

    &lt;network&gt;
        &lt;port auto-increment="false"&gt;5701&lt;/port&gt;
            &lt;outbound-ports&gt;
                &lt;ports&gt;49000,49001,49002,49003&lt;/ports&gt;
            &lt;/outbound-ports&gt;
        &lt;join&gt;
            &lt;multicast enabled="false"/&gt;
            &lt;kubernetes enabled="true"&gt;
                &lt;namespace&gt;default&lt;/namespace&gt;
                &lt;service-name&gt;my-app-cluster-hazelcast&lt;/service-name&gt;
            &lt;/kubernetes&gt;
        &lt;/join&gt;
    &lt;/network&gt;
&lt;/hazelcast&gt;
</code></pre>

<p>hazelcast-client.xml:</p>

<pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;hazelcast-client
        xsi:schemaLocation="http://www.hazelcast.com/schema/client-config http://www.hazelcast.com/schema/client-config/hazelcast-client-config-3.11.xsd"
        xmlns="http://www.hazelcast.com/schema/client-config"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;

    &lt;properties&gt;
        &lt;property name="hazelcast.logging.type"&gt;slf4j&lt;/property&gt;
    &lt;/properties&gt;

    &lt;connection-strategy async-start="false" reconnect-mode="ON"&gt;
        &lt;connection-retry enabled="true"&gt;
            &lt;initial-backoff-millis&gt;1000&lt;/initial-backoff-millis&gt;
            &lt;max-backoff-millis&gt;60000&lt;/max-backoff-millis&gt;
        &lt;/connection-retry&gt;
    &lt;/connection-strategy&gt;

    &lt;network&gt;
        &lt;kubernetes enabled="true"&gt;
            &lt;namespace&gt;default&lt;/namespace&gt;
            &lt;service-name&gt;my-app-cluster-hazelcast&lt;/service-name&gt;
        &lt;/kubernetes&gt;
    &lt;/network&gt;
&lt;/hazelcast-client&gt;
</code></pre>

<p>Expected result:</p>

<p>The service is able to connect to the pods, creating endpoints in its description.</p>

<p>$ kubectl describe service my-app-cluster-hazelcast</p>

<pre><code>Name:              my-app-cluster-hazelcast
Namespace:         default
Labels:            &lt;none&gt;
Annotations:       kubectl.kubernetes.io/last-applied-configuration:
                     {"apiVersion":"v1","kind":"Service","metadata":{"annotations":{},"name":"my-app-cluster-hazelcast","namespace":"default"},"spec":{"ports...
Selector:          app=my-app
Type:              ClusterIP
IP:                10.244.28.132
Port:              hazelcast  5701/TCP
TargetPort:        5701/TCP
Endpoints:         10.244.4.10:5701,10.244.4.9:5701
Session Affinity:  None
Events:            &lt;none&gt;
</code></pre>

<p>The application runs properly and shows two members in its hazelcast cluster and the deployment is shown as ready, the application can be fully accessed:</p>

<p>logs:</p>

<pre><code>2019-08-26 23:07:36,614 TRACE [hz._hzInstance_1_dev.InvocationMonitorThread] (com.hazelcast.spi.impl.operationservice.impl.InvocationMonitor): [10.244.4.10]:5701 [dev] [3.11] Broadcasting operation control packets to: 2 members
</code></pre>

<p>$ kubectl get deployments</p>

<pre><code>NAME                  READY   UP-TO-DATE   AVAILABLE   AGE
my-app-deployment   2/2     2            2           2m27s
</code></pre>

<p>Actual Result:</p>

<p>The service doesn't get any endpoint.</p>

<p>$ kubectl describe service my-app-cluster-hazelcast</p>

<pre><code>Name:              my-app-cluster-hazelcast
Namespace:         default
Labels:            &lt;none&gt;
Annotations:       kubectl.kubernetes.io/last-applied-configuration:
                     {"apiVersion":"v1","kind":"Service","metadata":{"annotations":{},"name":"my-app-cluster-hazelcast","namespace":"default"},"spec":{"ports...
Selector:          app=my-app
Type:              ClusterIP
IP:                10.244.28.132
Port:              hazelcast  5701/TCP
TargetPort:        5701/TCP
Endpoints:
Session Affinity:  None
Events:            &lt;none&gt;
</code></pre>

<p>The application gets stuck with the connection-strategy enabled in hazelcast-client.xml with the following logs, keeping its own cluster with no communication and the deployment in a non-ready state forever:</p>

<p>logs:</p>

<pre><code>22:54:11.236 [hz.client_0.cluster-] WARN com.hazelcast.client.connection.ClientConnectionManager - hz.client_0 [dev] [3.11] Unable to get alive cluster connection, try in 57686 ms later, attempt 52 , cap retrytimeout millis 60000
22:55:02.036 [hz._hzInstance_1_dev.cached.thread-4] DEBUG com.hazelcast.internal.cluster.impl.MembershipManager - [10.244.4.8]:5701 [dev] [3.11] Sending member list to the non-master nodes:

Members {size:1, ver:1} [
        Member [10.244.4.8]:5701 - 6a4c7184-8003-4d24-8023-6087d68e9709 this
]

22:55:08.968 [hz.client_0.cluster-] WARN com.hazelcast.client.connection.ClientConnectionManager - hz.client_0 [dev] [3.11] Unable to get alive cluster connection, try in 51173 ms later, attempt 53 , cap retrytimeout millis 60000
22:56:00.184 [hz.client_0.cluster-] WARN com.hazelcast.client.connection.ClientConnectionManager - hz.client_0 [dev] [3.11] Unable to get alive cluster connection, try in 55583 ms later, attempt 54 , cap retrytimeout millis 60000
</code></pre>

<p>$ kubectl get deployments</p>

<pre><code>NAME                  READY   UP-TO-DATE   AVAILABLE   AGE
my-app-deployment   0/2     2            0           45m
</code></pre>

Nicolas
<p>Just to clarify:</p>

<p>As described by <a href="https://stackoverflow.com/users/11019984/cristian-cordova">OP</a> with reference to <a href="https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-probes/" rel="nofollow noreferrer">readiness probe</a>: </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. <strong>When a Pod is not ready, it is removed from Service load balancers</strong></p>
</blockquote>
