如何创建将基于体系结构部署的k8s部署文件

时间:2018-05-18 05:44:28

标签: kubernetes kubernetes-deployment

我编写的部署文件如下,这给我的错误为unknown field "platform"。是否有任何关于指定内容以便基于架构进行部署的想法?

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

3 个答案:

答案 0 :(得分:2)

您必须在部署规范上使用nodeAffinity定义。这是我用来将任务固定到amd64或arm主机的示例:

import tkinter as tk
from tkinter.ttk import *

master = tk.Tk()
master.title("Gas Calculator")
v = tk.IntVar()
combo = Combobox(master)

def callback(eventObject):
    # you can also get the value off the eventObject
    print(eventObject.widget.get())
    # to see other information also available on the eventObject
    print(dir(eventObject))

comboARU = Combobox(master)
comboARU['values']= ("Acres", "Ft^2")
comboARU.current(0) #set the selected item
comboARU.grid(row=3, column=2)
comboARU.bind("<<ComboboxSelected>>", callback)

master.mainloop()

您可以使用任意键和值。这是documented example

答案 1 :(得分:1)

如果查看specification of a container - 没有为platform定义字段 - 那么您的错误与部署YAML中的错误有关。您必须从YAML中移除以下块以进行制作 工作(清单中没有其他问题):

platform:
          architecture: ppc64le
          os: linux

其次AFAIK,你要做的是不可能的。我可以建议两种方法作为替代方案:

  1. 如果您使用的是helm,则可以参数化Nginx图像的版本,然后根据您对目标操作系统架构的了解动态传递它。

    • name:nginx     image:nginx:{{version}}     端口:      - containerPort:80
  2. 第二种方法是使用污点和容忍或节点关联来调度具有适当操作系统的节点上的pod。这也意味着您将不得不进行多次部署 - 每种架构一次。

  3. taints和tolerations documentation can be found here的详细信息 节点和节点的细节pod affinity can be found here

答案 2 :(得分:0)

在导航对 kubernetes 集群状态建模的资源时注意 kubectl explain 很有用。

所以对于模板下spec中字段的描述,可以在部署spec中描述pods,可以运行命令

kubectl explain deployment.spec.template.spec

并得到

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

我已经剪掉了上面的输出,还有很多内容要阅读。

如果您只想要字段名称,请使用 --recursive 标志

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

输出的摘录...

 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> 

以上内容适用于在命令行中工作。

在编辑器中,您可以使用 YAML Language Server 进行自动完成和验证。