No matches for kind of Deployment in version/extensionsb1beta1 while running the app on kubernetes 1.18

12/7/2020

This is my kubernetes.yml

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: servicetwo
  labels:
    name: servicetwo
  namespace: sock-shop
spec:
  replicas: 1
  template:
    metadata:
      labels:
        name: servicetwo
    spec:
      containers:
      - name: servicetwo
        image: nik/pythonserviceone
        ports:
         - containerPort: 5000
        
---
apiVersion: v1
kind: Service
metadata:
  name: servicetwo
  labels:
    name: servicetwo
  namespace: sock-shop
spec:
  ports:
    # the port that this service should serve on
  - port: 5000
    targetPort: 5000
    nodePort: 30003
  selector:
    name: servicetwo
  type: NodePort  
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: servicethree
  labels:
    name: servicethree
  namespace: sock-shop
spec:
  replicas: 1
  template:
    metadata:
      labels:
        name: servicethree
    spec:
      containers:
      - name: servicetwo
        image: nik/pythonservicetwo
        ports:
         - containerPort: 7000
---
apiVersion: v1
kind: Service
metadata:
  name: servicethree
  labels:
    name: servicethree
  namespace: sock-shop
spec:
  ports:
    # the port that this service should serve on
  - port: 7000
    targetPort: 7000
    nodePort: 30002
  selector:
    name: servicethree
  type: NodePort 
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: apigateway
  labels:
    name: apigateway
  namespace: sock-shop
spec:
  replicas: 1
  template:
    metadata:
      labels:
        name: apigateway
    spec:
      containers:
      - name:  apigateway
        image: ni/aggregatornew
        ports:
        - containerPort: 9000
        
---
apiVersion: v1
kind: Service
metadata:
  name:  apigateway
  labels:
    name:  apigateway
  namespace: sock-shop
spec:
  type: NodePort
  ports:
  - port: 9000
    targetPort: 9000
    nodePort: 30001
  selector:
    name: apigateway
---

I know this error is because of new version of kubernetes ,but I am unable to fix the issue ,when I change extensions/v1beta1 to apps/v1 I start getting error servicetwo not found while running kubectl apply -f kubernets.yml.With kuberentes 1.10 its running perfectly ,any help would be really appreciated thanks

-- gANDALF
docker
kubernetes

1 Answer

12/7/2020

In addition to change to apps/v1 you also need to add the new required field selector: in the spec:

something like this should work for you:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: servicetwo
  labels:
    name: servicetwo
  namespace: sock-shop
spec:
  replicas: 1
  selector:               // new required field
    matchLabels:
      name: servicetwo     // must match your labels
  template:
    metadata:
      labels:
        name: servicetwo
    spec:
      containers:
      - name: servicetwo
        image: nik/pythonserviceone
        ports:
         - containerPort: 5000
-- Jonas
Source: StackOverflow