<p>So I have a deployment job that runs some kubectl commands.
A configuration file is modified to use the latest docker image SHA, and I run these commands to deploy it out:</p>
<pre><code>kubectl apply -f myconfig-file.yaml
#we have to scale up temporarily due to reasons beyond the purview of this question
kubectl scale -f myconfig-file.yaml --replicas=4
#* wait a minute or so *
sleep 60
kubectl scale -f myconfig-file.yaml --replicas=2
</code></pre>
<p>Apply correctly updates the replicationcontroller definition on Google Cloud to be pointed at the latest image, but the original containers still remain. Scaling up DOES create containers with the correct image, but once I scale down, it removes the newest containers, leaving behind the old containers with the old image.</p>
<p>I have confirmed that:</p>
<ol>
<li>The new containers with their new image are working as expected.</li>
<li>I ended up doing the deployment manually and manually removed the old containers, (and k8s correctly created two new containers with the latest image) and when I scaled down, the new containers with the new images stuck around.  My application worked as expected.</li>
</ol>
<p>My yaml file in question:</p>
<pre><code>apiVersion: v1
kind: ReplicationController
metadata:
  name: my-app-cluster
spec:
  replicas: 2
  template:
    metadata:
      labels:
        run: my-app-cluster
    spec:
      containers:
      - image: mySuperCoolImage@sha256:TheLatestShaHere
        imagePullPolicy: Always
        name: my-app-cluster
        ports:
        - containerPort: 8008
          protocol: TCP
      terminationGracePeriodSeconds: 30
</code></pre>
<p>I'm using the Google Cloud K8s FWIW. Do I need to do something in the YAML file to instruct k8s to destroy the old instances?</p>

Another Stackoverflow User
<p>So it looks like the majority of my problem stem from the fact that I'm using a <code>ReplicationController</code> instead of a more supported <code>Deployment</code> or a <code>ReplicaSet</code>. Unfortunately, at this time, I'll need to consult with my team on the best way to migrate to that format since there are some considerations we have.</p>
<p>In the meantime, I fixed the issue with this little hack.</p>
<pre><code>oldPods=($(kubectl get pods | grep myPodType | perl -wnE'say /.*-myPodType-\w*/g'))

#do the apply and scale thing like listed above
#then delete
for item in ${oldPods[@]}; do kubectl delete pod $item; done
</code></pre>
