kubernetes: selector field missing in kompose

12/21/2017

I have a docker-compose.yml file we have been using to set up our development environment.

The file declares some services, all of them more or less following the same pattern:

services:

   service_1:
      image: some_image_1
      enviroment:
        - ENV_VAR_1
        - ENV_VAR_2
     depends_on:
        - another_service_of_the_same_compose_file

In the view of migrating to kubernetes, when running:

kompose convert -f docker-compose.yml 

produces, for each service, a pair of deployment/service manifests.

Two questions about the deployment generated:

1.

the examples in the official documentation seem to hint that the selector field is needed for a Deployment to be aware of the pods to manage.

However the deployment manifests created do not include a selector field, and are as follows:

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  annotations:
    kompose.cmd: kompose convert -f docker-compose.yml
    kompose.version: 1.6.0 (e4adfef)
  creationTimestamp: null
  labels:
    io.kompose.service: service_1
  name: service_1
spec:
  replicas: 1
  strategy: {}
  template:
    metadata:
      creationTimestamp: null
      labels:
        io.kompose.service: service_1
    spec:
      containers:
      - image: my_image
        name: my_image_name
        resources: {}
      restartPolicy: Always
status: {}

2.

the apiVersion in the generated deployment manifest is extensions/v1beta1, however the examples in the Deployments section of the official documentation default to apps/v1. The recommendation seems to be

for versions before 1.9.0 use apps/v1beta2

Which is the correct version to use? (using kubernetes 1.8)

-- pkaramol
kubernetes

3 Answers

2/14/2020

In kubernetes 1.16 the deployment's spec.selector became required. Kompose (as of 1.20) does not yet do this automatically. You will have to add this to every *-deployment.yaml file it creates:

  selector:
    matchLabels:
      io.kompose.service: alignment-processor

If you use an IDE like jetbrains you can use the following search/replace patterns on the folder where you put the conversion results:

Search for this multiline regexp:

    io.kompose.service: (.*)
  name: \1
spec:
  replicas: 1
  template:

Replace with this pattern:

    io.kompose.service: $1
  name: $1
spec:
  replicas: 1
  selector:
    matchLabels:
      io.kompose.service: $1
  template:

The (.*) captures the name of the service, the \1 matches the (first and only) capture, and the $1 substitutes the capture in the replacement.

You will also have to substitute all extensions/v1beta1 with apps/v1 in all *-deployment.yaml files.

I also found that secrets have to massaged a bit but this goes beyond the scope of this question.

-- Oliver
Source: StackOverflow

12/21/2017

Let's begin by saying that Kubernetes and Kompose are two different independent systems. Kompose is trying to match all of the dependency with kubernetes.

At the moment all of the selector's fields are generated by kubernetes.In future, It might be done by us.

If you would like to check your selector's fields use following commands

kubectl get deploy 

kubectl describe deploy DEPLOY_NAME 

After version k8s 1.9 all of the long-running objects would be part of /apps group.

We’re excited to announce General Availability (GA) of the apps/v1 Workloads API, which is now enabled by default. The Apps Workloads API groups the DaemonSet, Deployment, ReplicaSet, and StatefulSet APIs together to form the foundation for long-running stateless and stateful workloads in Kubernetes. Note that the Batch Workloads API (Job and CronJob) is not part of this effort and will have a separate path to GA stability.

I have attached the link for further research

kubernetes-19-workloads

-- Suresh Vishnoi
Source: StackOverflow

12/22/2017
  1. As a selector field isn't required for deployments and Kompose doesn't know your cluster's nodes, it doesn't set a selector (which basically tells k8s in which nodes run pods).

  2. I wouldn't edit apiversion cause Kompose assumes that version defining the rest of the resource. Also, if you are using kubernetes 1.8 read 1.8 docs https://v1-8.docs.kubernetes.io/docs/

-- Gabriel Miretti aka gmiretti
Source: StackOverflow