Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing selector in postgres-deployment.yaml? #31

Open
4everinbeta opened this issue Jan 23, 2020 · 2 comments
Open

Missing selector in postgres-deployment.yaml? #31

4everinbeta opened this issue Jan 23, 2020 · 2 comments

Comments

@4everinbeta
Copy link

4everinbeta commented Jan 23, 2020

I'm getting the following error when I attempt to create the postgres-deployment.yaml

error: error validating "postgres-deployment.yml": error validating data: ValidationError(Deployment.spec): missing required field "selector" in io.k8s.api.apps.v1.DeploymentSpec; if you choose to ignore these errors, turn validation off with --validate=false

I can ignore it for now but it seems like something that should be demonstrated to the current spec. Or am I (very likely) missing something?

UPDATE

I actually can't seem to ignore it. Now I feel confident I am doing something wrong.

The Deployment "postgres" is invalid:
* spec.selector: Required value
* spec.template.metadata.labels: Invalid value: map[string]string{"app":"postgres"}: `selector` does not match template `labels`

UPDATE 2

By rolling back the api version it works. But I'm still not sure that is the correct solution?

apiVersion: apps/v1beta1

@burrsutter
Copy link
Owner

I apologize for the confusion: That is an old apiVersion that I need to clean up. Currently apiVersion for Deployment yaml is "apiVersion: apps/v1"

@springified
Copy link

I've added

selector:
    matchLabels:
      app: postgres

and be able to create postgres pod.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: postgres
spec:
  selector:
    matchLabels:
      app: postgres
  replicas: 1
  template:
    metadata:
      labels:
        app: postgres
    spec:
      containers:
        - name: postgres
          image: postgres:10.5
          imagePullPolicy: "IfNotPresent"
          env:
            - name: POSTGRES_DB
              value: postgresdb
            - name: POSTGRES_USER
              value: admin
            - name: POSTGRES_PASSWORD
              value: adminS3cret
          ports:
            - containerPort: 5432
              name: postgres
          volumeMounts:
            # mountPath within the container
            - name: postgres-pvc
              mountPath: "/var/lib/postgresql/data/:Z"
      volumes:
        # mapped to the PVC
        - name: postgres-pvc
          persistentVolumeClaim:
            claimName: postgres-pvc

`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants