Is there something like Swarm's Task-Slot in Kubernetes? Is there something like Swarm's Task-Slot in Kubernetes? kubernetes kubernetes

Is there something like Swarm's Task-Slot in Kubernetes?


11 Months late, but here is the solution:

To get stable container (pod) names within K8S you must use a StatefulSet. StatefulSets are designed for applications that must maintain state, however, if you aren't using K8S volumes for state (keeping them ephemeral) you can use StatefulSets without an issue. There is a simple process of converting your Deployment to a StatefulSet:

  1. Change your apiVersion: to apps/v1
  2. Change the kind: to StatefulSet
  3. Under spec: add the selector: tag. This tag will contain everything you use to select the appropriate service. In addition you must ensure that any items you have under spec:template:metadata:labels match those under spec:selector:matchLabels (This will make more sense in the provided example)
  4. If you have any sort of update strategy, called strategy in a Deployment, change this to updateStrategy. For future reference, if you do not update this, you will end up with both a StatefulSet and a ReplicaSet being deployed as K8S is trying to fill the strategy and your StatefulSet requirements.

After applying these changes, you will have your StatefulSet deployed. How do we get task slots from this? The hostname.

Since K8S is maintaining stable pod names, you will have names such as:

pod/mypod-0                             1/1     Running   0          10mpod/mypod-1                             1/1     Running   0          9m

when running kubetctl. After that, it is a simple matter of parsing the number out of your pod name.

Below is the YAML for a StatefulSet:

apiVersion: apps/v1kind: StatefulSetmetadata:  name: myStatefulSetName  labels:    app: SomeLabel1    label2: SomeLabel2spec:  replicas: 100  selector:    matchLabels:        app: SomeLabel1        label2: SomeLabel2  updateStrategy:    type: RollingUpdate  template:    metadata:      labels:        app: SomeLabel1        label2: SomeLabel2    spec:      containers:      - name: myPodName        image: myPod:latest        imagePullPolicy: Always        ports:        - name: myPodPort          containerPort: 8080

The differences become apparent on a equivalent Deployment:

apiVersion: extensions/v1beta1kind: Deploymentmetadata:  name: myDeploymentName  labels:    app: SomeLabel1    label2: SomeLabel2spec:  replicas: 100  strategy:    type: RollingUpdate  template:    metadata:      labels:        app: SomeLabel1        label2: SomeLabel2    spec:      containers:      - name: myPodName        image: myPod:latest        imagePullPolicy: Always        ports:        - name: myPodPort          containerPort: 8080