Reputation: 12123
I created a Dockerfile for running Jupyter in Docker.
FROM ubuntu:latest
FROM python:3.7
WORKDIR /app
ADD . /app
RUN pip install -r requirements.txt
CMD ["jupyter", "notebook", "--allow-root", "--ip=0.0.0.0"]
My requirements.txt file looks like this:
jupyter
git+https://github.com/kubernetes-client/python.git
I ran docker build -t hello-jupyter .
and it builds fine. Then I ran docker run -p 8888:8888 hello-jupyter
and it runs fine.
I'm able to open Jupyter notebook in a web browser (127.0.0.1:8888) when I run the Docker image hello-jupyter.
Now I would like to run Jupyter as a Kubernetes deployment. I created this deployment.yaml file:
apiVersion: v1
kind: Service
metadata:
name: hello-jupyter-service
spec:
selector:
app: hello-jupyter
ports:
- protocol: "TCP"
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
I ran this command in shell:
$ kubectl apply -f deployment.yaml
service/hello-jupyter-service unchanged
deployment.apps/hello-jupyter unchanged
When I check my pods, I see crash loops
$ 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
The pods have crash loop as their status and I'm not able to open Jupyter in a web browser.
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?
Here is the log of one of my pods:
$ 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 "/usr/local/lib/python3.7/site-packages/traitlets/traitlets.py", line 537, in get
value = obj._trait_values[self.name]
KeyError: 'port'
I do specify a port in my deployment.yaml file. I'm not sure why I get this error in the log.
Upvotes: 1
Views: 592
Reputation: 841
There are many reasons on getting the CrashLoopBackOff
error. In your case, it seems like your deployment file is locked or a lack of resources prevents the container from loading.
As I understood, you've built docker image locally and added it to your local Docker registry. Since imagePullPolicy: Never
specified and there is no error ErrImageNeverPull
, so there is no problem with your docker registries between your local docker and kubernetes.
You can start by running the command: kubectl describe pod [name]
to get more from kubelet.
Unless, try deploying single pod first instead of deployment with 4 replicas to make sure that kubernetes runs your image correctly.
Upvotes: 1