R_SS
R_SS

Reputation: 355

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

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

Upvotes: 2

Views: 2218

Answers (3)

Rob Kielty
Rob Kielty

Reputation: 8152

It's useful to be aware of kubectl explain when navigating resources that model the state of a kubernetes cluster.

So for descriptions of the fields in the spec under the template to describe the pods in a deployment spec, you can run the command

kubectl explain deployment.spec.template.spec

and get

KIND:     Deployment
VERSION:  apps/v1

RESOURCE: spec <Object>

DESCRIPTION:
     Specification of the desired behavior of the pod. More info:
     https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status

     PodSpec is a description of a pod.

FIELDS:
   activeDeadlineSeconds        <integer>
     Optional duration in seconds the pod may be active on the node relative to
     StartTime before the system will actively try to mark it failed and kill
     associated containers. Value must be a positive integer.

   affinity     <Object>
     If specified, the pod's scheduling constraints

   automountServiceAccountToken <boolean>
     AutomountServiceAccountToken indicates whether a service account token
     should be automatically mounted.

   containers   <[]Object> -required-
     List of containers belonging to the pod. Containers cannot currently be
     added or removed. There must be at least one container in a Pod. Cannot be
     updated

I've snipped the output above, there is a lot more to read.

and if you just want the field names use the --recursive flag

kubectl explain deployment.spec.template.spec --recursive 

an excerpt of the output ...

 podAffinity       <Object>
     preferredDuringSchedulingIgnoredDuringExecution        <[]Object>
        podAffinityTerm     <Object>
           labelSelector    <Object>
              matchExpressions      <[]Object>
                 key        <string>
                 operator   <string>
                 values     <[]string>
              matchLabels   <map[string]string>
           namespaces       <[]string>
           topologyKey      <string>
        weight      <integer>
     requiredDuringSchedulingIgnoredDuringExecution <[]Object>
        labelSelector       <Object>
           matchExpressions <[]Object>
              key   <string>
              operator      <string>
              values        <[]string>
           matchLabels      <map[string]string>
        namespaces  <[]string>
        topologyKey <string> 

The above is good for working at the command line.

In editor, you can make use of the YAML Language Server, for auto-completion and validation.

Upvotes: 0

Vishal Biyani
Vishal Biyani

Reputation: 4407

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

Upvotes: 2

Joseph
Joseph

Reputation: 31

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

Upvotes: 3

Related Questions