6
votes

I am new to kubernetes. Recently set up kubernetes cluster with 1 master and 1 node.

I am able to start a docker container by running sudo docker run <docker-image> in my node machine.

But i failed to start docker container as a pod using kubernetes yml file. by running sudo kubectl create -f deployment.yml

I describe the pod information and saw this error message.

      Last State:   Terminated
      Reason:       ContainerCannotRun
      Message:      OCI runtime create failed: container_linux.go:345: starting container process caused "exec: \"HOSTNAME\": executable file not found in $PATH": unknown
      Exit Code:    128

docker container supposes to start a java executable. this is my deployment file

kind: Service
apiVersion: v1
metadata:
  name: service1-service
spec:
  selector:
    app: service1
  ports:
    - protocol: "TCP"
      # Port accessible inside cluster
      port: 26666
      # Port to forward to inside the pod
      targetPort: 26666
      # Port accessible outside cluster
      nodePort: 26666
  type: LoadBalancer

---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: service1-depolyment
spec:
  selector:
    matchLabels:
      app: service1
  replicas: 1
  template:
    metadata:
      labels:
        app: service1
    spec:
      containers:
        - name: service1
          image: service1-docker-image
          imagePullPolicy: Never
          ports:
            - containerPort: 26666
          # args: ["HOSTNAME", "KUBERNETES_PORT"]

In this deployment file, I try to create a nginx and one java web applicaition service.

It is because i defined wrong apiVersion and kind ?

Any help would be appreciated.

1
The error message matches the commented-out args: line, FWIW. When you run the image locally, do you pass any options to docker run besides -p and maybe -d? - David Maze
when i run locally, i will use something like this sudo docker run -d -p 80:26666 service1-docker-image - John
You cloud delete the line of "HOSTNAME" and give a try. - todaynowork
Could you specify what are you expecting? According to kubernetes.io/docs/tasks/inject-data-application/… "If you supply only args for a Container, the default Entrypoint defined in the Docker image is run with the args that you supplied." Can you provide your Dockerfile? Are using microk8s/minikube/cloud? On GCP I received error about nodePort: The Service "service1-service" is invalid: spec.ports[0].nodePort: Invalid value: 26666: provided port is not in the valid range. The range of valid ports is 30000-32767 - PjoterS
@PjoterS provided ports can be configured from here. /etc/kubernetes/manifests/kube-apiserver.yam add one more config --service-node-port-range=20000-32767 - John

1 Answers

2
votes

Look at this error exec: \"HOSTNAME\": executable file not found in $PATH

I had a similar error since the container could not locate the docker "CMD" binary since I gave it the wrong path. Check the path to the file and that should do the trick.