<p>I created a Dockerfile for running Jupyter in Docker.</p>
<pre><code>FROM ubuntu:latest
FROM python:3.7

WORKDIR /app
ADD . /app

RUN pip install -r requirements.txt

CMD [&quot;jupyter&quot;, &quot;notebook&quot;, &quot;--allow-root&quot;, &quot;--ip=0.0.0.0&quot;]
</code></pre>
<p>My requirements.txt file looks like this:</p>
<pre><code>jupyter
git+https://github.com/kubernetes-client/python.git
</code></pre>
<p>I ran <code>docker build -t hello-jupyter .</code> and it builds fine. Then I ran <code>docker run -p 8888:8888 hello-jupyter</code> and it runs fine.</p>
<p>I'm able to open Jupyter notebook in a web browser (127.0.0.1:8888) when I run the Docker image hello-jupyter.</p>
<hr>
<p>Now I would like to run Jupyter as a Kubernetes deployment. I created this deployment.yaml file:</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: hello-jupyter-service
spec:
  selector:
    app: hello-jupyter
  ports:
  - protocol: &quot;TCP&quot;
    port: 8888
    targetPort: 8888
  type: LoadBalancer


---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: hello-jupyter
spec:
  replicas: 4
  selector:
    matchLabels:
      app: hello-jupyter
  template:
    metadata:
      labels:
        app: hello-jupyter
    spec:
      containers:
      - name: hello-jupyter
        image: hello-jupyter
        imagePullPolicy: Never
        ports:
        - containerPort: 8888
</code></pre>
<p>I ran this command in shell:</p>
<pre><code>$ kubectl apply -f deployment.yaml
service/hello-jupyter-service unchanged
deployment.apps/hello-jupyter unchanged
</code></pre>
<p>When I check my pods, I see crash loops</p>
<pre><code>$ kubectl get pods
NAME                             READY   STATUS             RESTARTS   AGE
hello-jupyter-66b88b5f6d-gqcff   0/1     CrashLoopBackOff   6          7m16s
hello-jupyter-66b88b5f6d-q59vj   0/1     CrashLoopBackOff   15         55m
hello-jupyter-66b88b5f6d-spvl5   0/1     CrashLoopBackOff   6          7m21s
hello-jupyter-66b88b5f6d-v2ghb   0/1     CrashLoopBackOff   6          7m20s
hello-jupyter-6758977cd8-m6vqz   0/1     CrashLoopBackOff   13         43m
</code></pre>
<p>The pods have crash loop as their status and I'm not able to open Jupyter in a web browser.</p>
<p>What is wrong with the deployment.yaml file? The deployment.yaml file simply runs the Docker image hello-jupyter in four different pods. Why does the Docker image run in Docker but not in Kubernetes pods?</p>
<p>Here is the log of one of my pods:</p>
<pre><code>$ kubectl logs hello-jupyter-66b88b5f6d-gqcff
[I 18:05:03.805 NotebookApp] Writing notebook server cookie secret to /root/.local/share/jupyter/runtime/notebook_cookie_secret
Traceback (most recent call last):
  File &quot;/usr/local/lib/python3.7/site-packages/traitlets/traitlets.py&quot;, line 537, in get
    value = obj._trait_values[self.name]
KeyError: 'port'
</code></pre>
<p>I do specify a port in my deployment.yaml file. I'm not sure why I get this error in the log.</p>

ktm5124
<p>There are many reasons on getting the <code>CrashLoopBackOff</code> error. In your case, it seems like your deployment file is locked or a lack of resources prevents the container from loading.</p>
<p>As I understood, you've built docker image locally and added it to your local Docker registry. Since <code>imagePullPolicy: Never</code> specified and there is no error <code>ErrImageNeverPull</code>, so there is no problem with your docker registries between your local docker and kubernetes.</p>
<p>You can start by running the command: <code>kubectl describe pod [name]</code> to get more from kubelet.</p>
<p>Unless, try deploying single pod first instead of deployment with 4 replicas to make sure that kubernetes runs your image correctly.</p>
