Im trying to create a pod using my local docker image as follow.
1.First I run this command in terminal
eval $(minikube docker-env)
2.I created a docker image as follow
sudo docker image build -t my-first-image:3.0.0 .
3.I created the pod.yml as shown below and I run this command
kubectl -f create pod.yml.
4.then i tried to run this command
kubectl get pods
but it shows following error
NAME READY STATUS RESTARTS AGE
multiplication-6b6d99554-d62kk 0/1 CrashLoopBackOff 9 22m
multiplication2019-5b4555bcf4-nsgkm 0/1 CrashLoopBackOff 8 17m
my-first-pod 0/1 CrashLoopBackOff 4 2m51
5.i get the pods logs
kubectl describe pod my-first-pod
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 6m22s default-scheduler Successfully assigned default/my-first-pod to minikube
Normal Pulled 5m20s (x4 over 6m17s) kubelet, minikube Successfully pulled image "docker77nira/myfirstimage:latest"
Normal Created 5m20s (x4 over 6m17s) kubelet, minikube Created container
Normal Started 5m20s (x4 over 6m17s) kubelet, minikube Started container
Normal Pulling 4m39s (x5 over 6m21s) kubelet, minikube pulling image "docker77nira/myfirstimage:latest"
Warning BackOff 71s (x26 over 6m12s) kubelet, minikube Back-off restarting failed container
Dockerfile
FROM node:carbon
WORKDIR /app
COPY . .
CMD [ "node", "index.js" ]
pods.yml
kind: Pod
apiVersion: v1
metadata:
name: my-first-pod
spec:
containers:
- name: my-first-container
image: my-first-image:3.0.0
index.js
var http = require('http');
var server = http.createServer(function(request, response) {
response.statusCode = 200;
response.setHeader('Content-Type', 'text/plain');
response.end('Welcome to the Golden Guide to Kubernetes
Application Development!');
});
server.listen(3000, function() {
console.log('Server running on port 3000');
});
Try checking logs with command kubectl logs -f my-first-pod
kind: Pod
apiVersion: v1
metadata:
name: my-first-pod
spec:
containers:
- name: my-first-container
image: my-first-image:3.0.0
command: [ "sleep" ]
args: [ "infinity" ]
I think your pod is getting terminated after execution of script inside index.js
I succeeded in running your image by performing these steps:
docker build -t foo .
then check if the container is working docker run -it foo
/app/index.js:5
response.end('Welcome to the Golden Guide to Kubernetes
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: Invalid or unexpected token
at createScript (vm.js:80:10)
at Object.runInThisContext (vm.js:139:10)
at Module._compile (module.js:617:28)
at Object.Module._extensions..js (module.js:664:10)
at Module.load (module.js:566:32)
at tryModuleLoad (module.js:506:12)
at Function.Module._load (module.js:498:3)
at Function.Module.runMain (module.js:694:10)
at startup (bootstrap_node.js:204:16)
at bootstrap_node.js:625:3
Not sure if this was the outcome you wanted to see, the container itself runs. But in Kubernetes it gets into ErrImagePull
Then after editing your Pod.yaml inspired by @Harsh Manvar it works fine with this. So the problem with exiting after completed command was just part of the problem.
apiVersion: v1
kind: Pod
metadata:
name: hello-pod
spec:
restartPolicy: Never
containers:
- name: hello
image: "foo"
imagePullPolicy: Never
command: [ "sleep" ]
args: [ "infinity" ]
This is Minikube so you can reuse the images, but if you would have more nodes this might not work at all. You can find a good explanation about using local docker images with Kubernetes here.