0

Actually I follow the manuals https://cloud.google.com/kubernetes-engine/docs/tutorials/hello-app#console to deploy web application tutorial. I made docker file and image at my local directory. And I uploaded the image to google cloud platform-container registry. The image is pushed to registry is success. And then I made kubernetes cluster and try to deploy it. But container got error "CrashLoopBackOff".

I deleted clusters and pods few times but nothing's changed. Error messages appeare when just container start.

Follow the docs the error is 'pods repeated start and crashed' and solution is watching logs carefully...

I searched other users case: such like ImagePullPolicy : always / restartPolicy : always but error not solved... enter image description here

ps: By the pods log..errorcode is 0

pps: Now I try to change container's yaml file. The imagePullPolicy ifnotPresent to Always. But

Pod "nginx-1-99dcd4d9f-84szv" is invalid: 
spec: Forbidden: pod updates may not change fields other than 
`spec.containers[*].image`, 
`spec.initContainers[*].image`, 
`spec.activeDeadlineSeconds` or 
`spec.tolerations` (only additions to existing tolerations)   

core.PodSpec{    
    Volumes: []core.Volume{
        {Name: "default-token-stk86", VolumeSource: core.VolumeSource{Secret: &core.SecretVolumeSource{SecretName: "default-token-stk86", DefaultMode: &420
                }
            }
        }
    },    InitContainers: nil,    Containers: []core.Container{
        {   
             TerminationMessagePath: "/dev/termination-log",    
             TerminationMessagePolicy: "File", 
             -  ImagePullPolicy: "Always", 
             +  ImagePullPolicy: "IfNotPresent",    
             SecurityContext: nil,    
             Stdin: false,
        },
    },    EphemeralContainers: nil,    RestartPolicy: "Always",
}

This error message appears.

Here is my Dockerfile. install settings and webpage for test 'phptest.php' To allow phptest.php I changed default file and init.sh

FROM    ubuntu
RUN     apt-get update && apt-get upgrade -y && \
        apt-get -y install \
        nginx \
        vim \
        php-fpm 
COPY    srcs/default /
COPY    srcs/phptest.php /
COPY    srcs/init.sh /
EXPOSE  80
CMD     bash init.sh

init.sh is here

rm /etc/nginx/sites-available/default
mv default /etc/nginx/sites-available/
mv phptest.php /var/www/html
chown -R www-data /var/www/*
chmod -R 755 /var/www/*
service nginx start
service php7.4-fpm start
bash

I uploaded new task because the post question was not meet to stackoverflow's guideline

Ze P
  • 1
  • 1
  • 1
    Hi there `CrashLoopBackOff` means the code in the container is crashing. Check the logs for the pod `kubectl logs pod/POD_NAME_HERE -n NAMESPACE_HERE` . Also the error you're getting about changing the ImagePullPolicy is saying you need to delete the pod and create it again – Justin Tamblyn Nov 19 '20 at 05:34

1 Answers1

1

Kubernetes containers can't run interactive shells for the most part, but that's what the main process in your container winds up being. (The image's CMD runs init.sh; that does some work including starting some helper processes and then runs bash; bash isn't running on a tty so it exits immediately; so the container exits as well; and since its container is in a start-and-exit-immediately loop, the pod goes into CrashLoopBackOff state.)

You should redesign this setup so that you have two separate Deployments, one running the PHP application and one running the Nginx reverse proxy. (And similarly two matching Services.) Each of these runs those processes directly as their image's CMD (do not try to use service). You should be able to test out a similar setup using Docker Compose or another lighter-weight tool before translating this back into the Kubernetes environment.

David Maze
  • 130,717
  • 29
  • 175
  • 215