How to create k8s deployment file which will deploy based on architecture

5/18/2018

I written deployment file as follow, which is giving me error as unknown field "platform". Any idea on what to specify so that it deploy based on architecture?

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.7.9
        ports:
        - containerPort: 80
        platform:
          architecture: amd64
          os: linux
      - name: nginx
        image: ppc64le/nginx:1.7.9
        ports:
        - containerPort: 80
        platform:
          architecture: ppc64le
          os: linux
-- Ravi _SS
kubernetes
kubernetes-deployment

2 Answers

5/18/2018

You have to use nodeAffinity definitions on your deployment spec. Here's an example I use to pin tasks to amd64 or arm hosts:

  affinity:
    nodeAffinity:
      requiredDuringSchedulingIgnoredDuringExecution:
        nodeSelectorTerms:
        - matchExpressions:
          - key: beta.kubernetes.io/arch
            operator: In
            values:
            - amd64

You can use arbitrary keys and values. Here's the documented example

-- Joseph
Source: StackOverflow

5/18/2018

If you look at the specification of a container - there is no field defined for platform - so your error is to do with a error in deployment YAML. You will have to remove following block from your YAML to make it work (Provided no other issues in manifest):

platform:
          architecture: ppc64le
          os: linux

Secondly AFAIK, what you are trying to do is not possible. There are two approaches which I can suggest as alternatives:

  1. If you are using helm, you can parameterize the version of Nginx image and then dynamically pass it based on your knowledge of target OS architecture.

    • name: nginx image: nginx:{{ version }} ports: - containerPort: 80
  2. The second approach is to use taints and tolerations or node affinity to schedule pods on the node with the appropriate OS. This also means you will have to potentially do multiple deployments - one for each architecture.

Details of taints and tolerations documentation can be found here Details of node & pod affinity can be found here

-- Vishal Biyani
Source: StackOverflow