my yaml file raised a erorr,can any one help me out

11/18/2019
apiVersion: v1
kind: Service
metadata:
   name: mongo
   labels:
     run: mongo
spec:
   ports:
    port: 27017
     targetPort: 27017
     protocol: TCP
   selector:
     run: mongo


apiVersion: extensions/v1beta1
kind: Deployment
metadata:
   name: mongo
spec:
   template:
     metadata:
       labels:
         run: mongo
     spec:
       containers:
        name: mongo
         image: mongo
         ports:
          containerPort: 27017
-- harish hari
kubernetes
yaml

1 Answer

11/18/2019

Try this:

apiVersion: v1
kind: Service
metadata:
  labels:
    run: mongo
  name: mongo
spec:
  ports:
  - port: 27017
    protocol: TCP
    targetPort: 27017
  selector:
    run: mongo

---
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    run: mongo
  name: mongo
spec:
  replicas: 1
  selector:
    matchLabels:
      run: mongo
  template:
    metadata:
      labels:
        run: mongo
    spec:
      containers:
      - image: mongo
        name: mongo

I generated it using:

kubectl run --image=mongo mongo --dry-run -o yaml

kubectl expose deployment mongo --port=27017 --dry-run -o yaml

-- FL3SH
Source: StackOverflow