将命名空间添加到kubernetes主机名

时间:2017-03-21 02:48:43

标签: kubernetes

目前我的pod都被命名为#34; some-deployment-foo-bar"当仅使用主机名报告错误时,这无法帮助我追踪问题。

所以我想要" $ POD_NAMESPACE。$ POD_NAME"作为主机名。

我尝试了pod.beta.kubernetes.io/hostname: "foo",但只设置了一个绝对名称......子域名不起作用......

我看到的唯一其他解决方案是使用包装器脚本来修改主机名然后执行实际命令......这非常hacky并且增加了每个容器的开销。

任何方式做得很好吗?

当前配置是:

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: foo
  labels:
    project: foo
spec:
  selector:
    matchLabels:
      project: foo
  template:
    metadata:
      name: foo
      labels:
        project: foo
    spec:
      containers:
      - image: busybox
        name: foo

1 个答案:

答案 0 :(得分:0)

PodSpec有一个子域字段,可用于指定Pod的子域。此字段值优先于pod.beta.kubernetes.io/subdomain注释值。

There is more information here,下面就是一个例子。

    apiVersion: v1
    kind: Service
    metadata:
      name: default-subdomain
    spec:
      selector:
        name: busybox
      clusterIP: None
      ports:
        - name: foo # Actually, no port is needed.
          port: 1234 
          targetPort: 1234
    ---
    apiVersion: v1
    kind: Pod
    metadata:
      name: busybox1
      labels:
        name: busybox
    spec:
      hostname: busybox-1
      subdomain: default-subdomain
      containers:
      - image: busybox
        command:
          - sleep
          - "3600"
        name: busybox
    ---
    apiVersion: v1
    kind: Pod
    metadata:
      name: busybox2
      labels:
        name: busybox
    spec:
      hostname: busybox-2
      subdomain: default-subdomain
      containers:
      - image: busybox
        command:
          - sleep
          - "3600"
        name: busybox