vaishal shah
vaishal shah

Reputation: 1

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

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 :)

Upvotes: 0

Views: 2330

Answers (3)

Muhammad Abdul Raheem
Muhammad Abdul Raheem

Reputation: 1980

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"]

Upvotes: 1

DT.
DT.

Reputation: 3561

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: {}

Upvotes: 0

Anmol Agrawal
Anmol Agrawal

Reputation: 904

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

Upvotes: 2

Related Questions