HiveBrain v1.2.0
Get Started
← Back to all entries
patternshelldockerMinor

Why will my container run in Docker, but will not run in Kubernetes?

Submitted by: @import:stackexchange-devops··
0
Viewed 0 times
whycontainerdockerkubernetesbutwillnotrun

Problem

Background

I have a container that I have defined with an CMD and an ENTRYPOINT in Docker. When I run the following command my container runs with no issues whatsoever.

docker run --rm -ti custom-container:latest


Here is the definition for my container:

FROM mcr.microsoft.com/powershell:6.2.3-ubuntu-bionic
COPY . /app
WORKDIR /app

CMD ["/app/Start-Test.ps1"]
ENTRYPOINT ["pwsh", "-f", "/app/Start-Test.ps1"]


The script Start-Test.ps1 is just an infinite loop that writes Hello World! to host.

Problem

When I go to run my container in Kubernetes, my container refuses to run.

Kubernetes is able to pull my image and it attempts to spin up the container, but I keep getting a status of BackedOff from Kubernetes.

I've gone through and tried to figure out why this is happening because the container runs perfectly fine in Docker.

I only have issues when I try to run the container in Kubernetes.

Here is the definition for my Kubernetes deployment.

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: my-custom-container
spec:
  replicas: 1
  selector:
    matchLabels:
      app: my-custom-container
  template:
    metadata:
      labels:
        app: my-custom-container
    spec:
      containers:
      - name: my-custom-container
        image: repository-url.io/custom-container:latest
      imagePullSecrets:
      - name: regcred


Question

What is the issue preventing my container from running when it runs with no problems in Docker?

Additionally, yes I would like to use PowerShell as my entry point. It should be possible to use any scripting langauge (bash, Ruby, Python, Perl, etc) as an entry point.

Solution

To debug this, check the container logs and the container events.

  • kubectl get pods



  • Find your pod name.



  • kubectl logs



  • If logs don't make it obvious...



  • kubectl get events



If you deployed into a namespace, make sure to add -n to all commands.

This should reveal basically everything. If you're stuck, you can also browse around the k8s dashboard if you haven't yet. But that probably wouldn't reveal much more than the CLI is with these commands.

Context

StackExchange DevOps Q#10695, answer score: 2

Revisions (0)

No revisions yet.