title: How to tell Kubernetes not to send traffic to a pod right after creation
body: <p>I have a Kubernetes nginx deployment that, when I redeploy it again with <code>kubectl apply -f file.yaml</code> it's having a small downtime, around 3 or 5 seconds.</p>
  <p>I'm using a readinessProbe to tell Kubernetes that traffic shouldn't be sent to that pod until the readiness works but as soon as the deployment begins (even while the <code>initialDelaySeconds</code> haven't finished I'm getting 502/503 errors that finish as soon as the readiness works.</p>
  <p>So, I thought that, until the readinessProbe is successful, that pod shouldn't be taken into account by Kubernetes, but that's not what I'm seeing.</p>
  <p>If I set up an <code>initialDelaySeconds</code> of 10, I get around 10 seconds of outage. If I reduce it to 0, I still have a small downtime, until the readiness works.</p>
  <p>The relevant parts of the service/deployment that I'm using are</p>
  <pre><code>---
  apiVersion: v1
  kind: Service
  metadata:
    name: 'name'
  spec:
    ports:
      - port: 80
        protocol: TCP
        name: http
    selector:
      project: 'project'
      role: bastion
    type: ClusterIP
  ---
  apiVersion: apps/v1
  kind: Deployment
  metadata:
    name: 'bastion'
  spec:
    replicas: 6
    strategy:
      rollingUpdate:
        maxSurge: 6
        maxUnavailable: 0
      type: RollingUpdate
    template:
      metadata:
      spec:
        containers:
          - name: 'bastion'
            image: 'my-image'
            imagePullPolicy: Always
            ports:
              - containerPort: 80
            lifecycle:
              preStop:
                exec:
                  command: ['sh', '-c', '/usr/sbin/nginx -s quit;']
            livenessProbe:
              httpGet:
                path: /myendpoint
                port: 80
              periodSeconds: 60
              initialDelaySeconds: 15
              failureThreshold: 15
            readinessProbe:
              httpGet:
                path: /myendpoint
                port: 80
            resources:
              requests:
                cpu: 5m
                memory: 5Mi
              limits:
                cpu: 50m
                memory: 50Mi
        imagePullSecrets:
          - name: 'imagesecrets'
  </code></pre>
  <p>Is there something that I'm missing here? What kind of changes I could try to debug/fix this problem?</p>