Fabric8 Java库以编辑现有资源

时间:2018-09-25 23:08:45

标签: java kubernetes fabric8

我想编辑一个入口,使其具有如下所示的另一条路径

现有入口:

apiVersion: extensions/v1beta1
    kind: Ingress
    metadata:
      name: test-ingress
      annotations:
        nginx.ingress.kubernetes.io/rewrite-target: /
    spec:
      rules:
      - http:
          paths:
          - path: /testpath
            backend:
              serviceName: test
              servicePort: 80

更新后的入口:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: test-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
  - http:
      paths:
      - path: /testpath
        backend:
          serviceName: test
          servicePort: 80

     - path: /newPath
        backend:
          serviceName: newService
          servicePort: 80

我想向现有入口的新路径添加新的后端。我正在使用fabric8 java库来实现此目标,

kubernetesClient.extensions().ingresses().inNamespace(my-env)
        .withName(ingressName).edit().editOrNewSpec().editFirstRule().editHttp()
        .addNewPathLike(path).withNewBackendLike(ingressBackend);

这将替换现有路径和后端。

apiVersion: extensions/v1beta1
    kind: Ingress
    metadata:
      name: test-ingress
      annotations:
        nginx.ingress.kubernetes.io/rewrite-target: /
    spec:
      rules:
      - http:
          paths:
          - path: /newPath
            backend:
              serviceName: newService
              servicePort: 80

我想念什么?

1 个答案:

答案 0 :(得分:1)

我相信您需要改用addToPaths(path)。像这样:

kubernetesClient.extensions().ingresses().inNamespace(my-env)
        .withName(ingressName).edit().editOrNewSpec().editFirstRule().editHttp()
        .addToPaths(path).withNewBackendLike(ingressBackend);

更多信息here