kubernetes Error -: error: unknown command "–f XXXX.yaml

2/22/2020

I am beginner for Kubernetes. I am trying to deploy in to Kubernetes container. I have created test.yaml file with below content.

apiVersion: v1
kind: pod
metadata:
   name: test
   spec:
      containers:
         - name: mongo
         image: mongo
         imagePullPolicy: Always
         command: ["echo", "SUCCESS"] 

When I am trying to run with below command it is throwing me error.

kubectl create -f test.yaml

Error -:

Error: must specify one of -f and -k


error: unknown command "–f test.yaml"
See 'kubectl create -h' for help and examples

Can you please help me where am I doing wrong. Thanks in advance :)

-- vaishal shah
docker
kubernetes
kubernetes-pod

3 Answers

2/22/2020

You can run simple pod just from command line as below using imperative command

kubectl run mongo --image=mongo --restart=Never --command -- echo success

You can generate a yaml by adding --dry-run -o yaml option to previous command.

$ kubectl run mongo --image=mongo --restart=Never --dry-run -o yaml --command -- echo success

apiVersion: v1
kind: Pod
metadata:
  creationTimestamp: null
  labels:
    run: mongo
  name: mongo
spec:
  containers:
  - command:
    - echo
    - success
    image: mongo
    name: mongo
    resources: {}
  dnsPolicy: ClusterFirst
  restartPolicy: Never
status: {}
-- DT.
Source: StackOverflow

2/22/2020

Your template's (yaml file) indentation is wrong.

Try this:

apiVersion: v1
kind: Pod
metadata:
   name: test
spec:
  containers:
     - name: mongo
       image: mongo
       imagePullPolicy: Always
       command: ["echo", "SUCCESS"]

spec was indented wrong, as well as image, imagePullPolicy and command. Also note the capital P on Pod

-- anmol agrawal
Source: StackOverflow

2/24/2020

Your yaml formatting is wrong. You can test it here: http://www.yamllint.com/

You also have some other kubernetes yaml structure and spelling mistakes.

This is the correct formatting and with correct spellings and structure:

apiVersion: v1
kind: Pod
metadata:
   name: test
spec:
   containers:
    - name: mongo
      image: mongo
      imagePullPolicy: Always
      command: ["echo", "SUCCESS"]
-- Muhammad Abdul Raheem
Source: StackOverflow