1

我正在尝试在 Kubernetes 中的我的服务对象上设置注释,但由于某种原因(即使 k8s 主服务器接受我的请求),注释也没有被设置。这是我的 YAML 文件:

---
apiVersion: v1
kind: Service
metadata:
  name: myapp
  labels:
    app: myapp
  annotations:
    service.beta.kubernetes.io/aws-load-balancer-ssl-cert: 'arn:aws:acm:us-west-2:<redacted>:certificate/<redacted>'
    service.beta.kubernetes.io/aws-load-balancer-ssl-negotiation-policy: 'ELBSecurityPolicy-TLS-1-2-2017-01'
    service.beta.kubernetes.io/aws-load-balancer-backend-protocol: 'http'   
    service.beta.kubernetes.io/aws-load-balancer-additional-resource-tags: 'app=myapp'
    service.beta.kubernetes.io/aws-load-balancer-access-log-enabled: true
spec:
  type: LoadBalancer
  selector:
    app: myapp-web
  ports:
    - protocol: TCP
      port: 80
      targetPort: 3000

然后我可以应用该文件而不会出错:

[ben@ubuntu simplenexus.com]$ kc apply -f deploy/k8s/service.yaml
service/myapp created

但是查询对象返回没有任何注释:

[ben@ubuntu simplenexus.com]$ kc get svc myapp -o yaml
apiVersion: v1
kind: Service
metadata:
  annotations:
    kubectl.kubernetes.io/last-applied-configuration: |
      {"apiVersion":"v1","kind":"Service","metadata":{"annotations":{},"labels":{"app":"myapp"},"name":"myapp","namespace":"default"},"spec":{"ports":[{"port":80,"protocol":"TCP","targetPort":3000}],        "selector":{"app":"myapp-web"},"type":"LoadBalancer"}}
  creationTimestamp: "2019-04-11T16:27:45Z"
  labels:
    app: myapp
  name: myapp
  namespace: default
  resourceVersion: "2085328"
  selfLink: /api/v1/namespaces/default/services/myapp
  uid: <redacted>
spec:
  clusterIP: <redacted>
  externalTrafficPolicy: Cluster
  ports:
  - nodePort: 32118
    port: 80
    protocol: TCP
    targetPort: 3000
  selector:
    app: myapp-web
  sessionAffinity: None
  type: LoadBalancer
status:
  loadBalancer:
    ingress:
    - hostname: <redacted>.us-west-2.elb.amazonaws.com

我可以手动设置注释,它们会保留:

[ben@ubuntu simplenexus.com]$ kc annotate svc myapp newannot=success
service/myapp annotated
[ben@ubuntu simplenexus.com]$ kc get svc myapp -o yaml
apiVersion: v1
kind: Service
metadata:
  annotations:
    kubectl.kubernetes.io/last-applied-configuration: |
      {"apiVersion":"v1","kind":"Service","metadata":{"annotations":{},"labels":{"app":"myapp"},"name":"myapp","namespace":"default"},"spec":{"ports":[{"port":80,"protocol":"TCP","targetPort":3000}],        "selector":{"app":"myapp-web"},"type":"LoadBalancer"}}
    newannot: success
  creationTimestamp: "2019-04-11T16:27:45Z"
  labels:
    app: myapp
  name: myapp
  namespace: default
  resourceVersion: "2085328"
  selfLink: /api/v1/namespaces/default/services/myapp
  uid: <redacted>
  ...

我做错了吗?在 YAML 文件中的 Kubernetes 服务对象上设置注释的正确方法是什么?

4

1 回答 1

2

事实证明,您不能在注释中使用布尔值,这是针对它的持续错误报告。注释值必须是字符串,因此您需要通过将值放在括号中来对其进行清理'...'

我部署了您的 YAML,它与:

    service.beta.kubernetes.io/aws-load-balancer-access-log-enabled: 'true'
于 2019-04-12T14:12:06.460 回答