-2

My docker-compose file is as below:

version: '3'

services:
    nginx:
        build: .
        container_name: nginx
        ports:
            - '80:80'

And my Dockerfile:

FROM nginx:alpine

I used kompose konvert and it created two files called nginx-deployment.yml and nginx-service.yml with the below contents.

nginx-deployment.yml:

apiVersion: apps/v1
kind: Deployment
metadata:
  annotations:
    kompose.cmd: kompose convert
    kompose.version: 1.22.0 (955b78124)
  creationTimestamp: null
  labels:
    io.kompose.service: nginx
  name: nginx
spec:
  replicas: 1
  selector:
    matchLabels:
      io.kompose.service: nginx
  strategy: {}
  template:
    metadata:
      annotations:
        kompose.cmd: kompose convert
        kompose.version: 1.22.0 (955b78124)
      creationTimestamp: null
      labels:
        io.kompose.service: nginx
    spec:
      containers:
        - image: nginx:alpine
          name: nginx
          ports:
            - containerPort: 80
          resources: {}
      restartPolicy: Always
status: {}

And nginx-service.yml:

apiVersion: v1
kind: Service
metadata:
  annotations:
    kompose.cmd: kompose convert
    kompose.version: 1.22.0 (955b78124)
  creationTimestamp: null
  labels:
    io.kompose.service: nginx
  name: nginx
spec:
  ports:
    - name: "80"
      port: 80
      targetPort: 80
  selector:
    io.kompose.service: nginx
status:
  loadBalancer: {}

My kustomization.yml:

resources:
        - nginx-deployment.yml
        - nginx-service.yml

All files are in the same path /home.

I run these three commands but for each of them I got a different error:

  1. kubectl apply -f kustomization.yml:
error: error validating "kustomization.yml": error validating data: [apiVersion not set, kind not set]; if you choose to ignore these errors, turn validation off with --validate=false
  1. kubectl apply -k .:
error: accumulating resources: accumulation err='accumulating resources from 'nginx-deployment.yml': evalsymlink failure on '/home/nginx-deployment.yml' : lstat /home/nginx-deployment.yml: no such file or directory': evalsymlink failure on '/home/nginx-deployment.yml' : lstat /home/nginx-deployment.yml: no such file or directory
  1. kubectl apply -f kustomization.yml --validate=false:
error: unable to decode "kustomization.yml": Object 'Kind' is missing in '{"resources":["nginx-deployment.yml","nginx-service.yml"]}'
  1. kubectl apply -k . --validate=false:
error: accumulating resources: accumulation err='accumulating resources from 'nginx-deployment.yml': evalsymlink failure on '/home/nginx-deployment.yml' : lstat /home/nginx-deployment.yml: no such file or directory': evalsymlink failure on '/home/nginx-deployment.yml' : lstat /home/nginx-deployment.yml: no such file or directory

The kubernetes is a single node.

Why I'm getting these errors and how may I run my container in this environment?

Jonas
  • 121,568
  • 97
  • 310
  • 388
Saeed
  • 3,255
  • 4
  • 17
  • 36
  • 1
    You should not apply `kustomization.yaml`. You should use `-k` but it looks like you don't have the files in the same directory as you run the command? – Jonas May 23 '21 at 17:36
  • @Jonas since then I figured out as @Faheem answered, that auto-generated file's extension is `yaml` but I point to `yml` file, so it says no such file or directory and that's pretty normal:) – Saeed May 23 '21 at 20:26

1 Answers1

4

Your Kustomization.yml file has two errors. The files generated by kompose have .yaml extensions but you are referring to .yml and you are missing the kind and apiVersion lines.

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

resources:
  - nginx-deployment.yaml
  - nginx-service.yaml
kubectl apply -k .
Faheem
  • 3,429
  • 19
  • 26
  • thanks, that was a point I did not notice regarding extension since I did not run `ls` command:) – Saeed May 23 '21 at 20:29