首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何创建基于架构部署的k8s部署文件

如何创建基于架构部署的k8s部署文件
EN

Stack Overflow用户
提问于 2018-05-18 13:44:28
回答 3查看 1.1K关注 0票数 2

我按如下方式编写了部署文件,这给出的错误是unknown field "platform"。你知道该指定什么才能基于架构进行部署吗?

代码语言:javascript
复制
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
EN

回答 3

Stack Overflow用户

发布于 2018-05-18 14:31:06

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

代码语言:javascript
复制
  affinity:
    nodeAffinity:
      requiredDuringSchedulingIgnoredDuringExecution:
        nodeSelectorTerms:
        - matchExpressions:
          - key: beta.kubernetes.io/arch
            operator: In
            values:
            - amd64

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

票数 3
EN

Stack Overflow用户

发布于 2018-05-18 14:30:35

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

代码语言:javascript
复制
platform:
          architecture: ppc64le
          os: linux

其次,AFAIK,你想要做的事情是不可能的。我可以推荐两种方法作为替代方案:

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

代码语言:javascript
复制
- name: nginx     image: nginx:{{ version }}     ports:     - containerPort: 80

  1. 第二种方法是使用污染和容差或节点亲和性在具有适当操作系统的节点上调度pods。这也意味着您可能需要执行多个部署-每个architecture.

一个

node & pod affinity can be found here的污点详情和tolerations documentation can be found here详情

票数 2
EN

Stack Overflow用户

发布于 2021-03-31 16:39:34

在导航模拟kubernetes集群状态的资源时,了解kubectl explain是很有用的。

因此,对于模板下的规范中的字段的描述,您可以运行以下命令

代码语言:javascript
复制
kubectl explain deployment.spec.template.spec

并获取

代码语言:javascript
复制
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标志

代码语言:javascript
复制
kubectl explain deployment.spec.template.spec --recursive 

输出的摘录...

代码语言:javascript
复制
 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进行自动完成和验证。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50404503

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档