<p>I'm novice in using Kubernetes, Docker and GCP, sorry if the question is stupid and (or) obvious.</p>

<p>I try to create simple gRPC server with http(s) mapping using as example Google samples. The issue is that my container can be started from Google cloud shell with no complains but fails on Kubernetes Engine after deployment.</p>

<p>In Google Cloud Console:</p>

<pre><code>git clone https://gitlab.com/myrepos/grpc.git
cd grpc
docker build -t gcr.io/project-id/python-grpc-diagnostic-server:v1 .

# Run the container "locally"
docker run --rm -p 8000:8000 gcr.io/mproject-id/python-grpc-diagnostic-server:v1                                    
Server is started
^CServer is stopped

# Pushing the image to Container Registry
gcloud docker -- push gcr.io/project-id/python-grpc-diagnostic-server:v1

# Deployment 
kubectl create -f grpc-diagnostic.yaml
</code></pre>

<p>In Deployment details 'diagnostic' container has "CrashLoopBackOff" status and in Logs the next error appears:</p>

<pre><code>File "/diagnostic/diagnostic_pb2.py", line 17, in &lt;module&gt;
    from google.api import annotations_pb2 as google_dot_api_dot_annotations__pb2
ModuleNotFoundError: No module named 'google.api'
</code></pre>

<p>Could you please give any idea why the same container starts in shell and fails on Kubernetes Engine?
Thanks.</p>

<p>requirements.txt</p>

<pre><code>grpcio
grpcio-tools
pytz
google-auth
googleapis-common-protos
</code></pre>

<p>Dockerfile</p>

<pre><code>FROM gcr.io/google_appengine/python

# Create a virtualenv for dependencies. This isolates these packages from
# system-level packages.
RUN virtualenv -p python3.6 /env

# Setting these environment variables are the same as running
# source /env/bin/activate.
ENV VIRTUAL_ENV -p python3.6 /env
ENV PATH /env/bin:$PATH

ADD . /diagnostic/

WORKDIR /diagnostic
RUN pip install -r requirements.txt

EXPOSE 8000

ENTRYPOINT ["python", "/diagnostic/diagnostic_server.py"]
</code></pre>

<p>grpc-diagnostic.yaml</p>

<pre><code>apiVersion: v1
kind: Service
metadata:
  name: esp-grpc-diagnostic
spec:
  ports:
  # Port that accepts gRPC and JSON/HTTP2 requests over HTTP.
  - port: 80
    targetPort: 9000 # or 8000?
    protocol: TCP
    name: http2
  selector:
    app: esp-grpc-diagnostic
  type: LoadBalancer
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: esp-grpc-diagnostic
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: esp-grpc-diagnostic
    spec:
      containers:
      - name: esp
        image: gcr.io/endpoints-release/endpoints-runtime:1
        args: [
          "--http2_port=9000",
          "--service=diagnostic.endpoints.project-id.cloud.goog",
          "--rollout_strategy=managed",
          "--backend=grpc://127.0.0.1:8000"
        ]
        ports:
          - containerPort: 9000
      - name: diagnostic
        image: gcr.io/project-id/python-grpc-diagnostic-server:v1
        ports:
          - containerPort: 8000
</code></pre>

<p>That was my stupid mistake. I changed the image, but the name of image was the same, so the cluster continued using the old wrong image thinking nothing changed.
The right way to redeploy a code is create image with new tag, for instance v1.01 and set the new image for existing deployment as it is described in <a href="https://cloud.google.com/kubernetes-engine/docs/tutorials/hello-app" rel="nofollow noreferrer">documentation</a>. I deleted the service and the deployment and recreated it again, but I didn't delete the cluster  thinking that I started from scratch.</p>

<p>Right way:</p>

<pre><code>docker build -t gcr.io/project-id/python-grpc-diagnostic-server:v1.01 . 
gcloud docker -- push gcr.io/project-id/python-grpc-diagnostic-server:v1.01   
kubectl set image deployment/esp-grpc-diagnostic diagnostic=gcr.io/project-id/python-grpc-diagnostic-server:v1.01
</code></pre>

<p>Another way pulling updated images with no name changed is changing <code>imagePullPolicy</code> that is set to <code>IfNotPresent</code> by default. <a href="https://kubernetes.io/docs/concepts/containers/images/#updating-images" rel="nofollow noreferrer">more info</a></p>
