Cannot create deployment by Java API, but can be created by kubectl

4/22/2018

My environment: k8s version 1.10. kubectl version 1.10

Java client library:

    <dependency>
        <groupId>io.kubernetes</groupId>
        <artifactId>client-java</artifactId>
        <version>1.0.0-beta4</version>
    </dependency>

When I use "kubectl create -f xxx.yml",Deployment created successfully. But using API, get "400 Bad Request" result. No other useful message. The result of K8s API always give out so little information for debugging. :(

Following is the full yaml of my deployment.

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: nginx-ingress-controller
  namespace: ingress-nginx
spec:
  replicas: 1
  template:
    metadata:
      name: nginx-ingress-controller
      labels:
        app: nginx-ingress-controller
      annotations:
        prometheus.io/port: '10254'
        prometheus.io/scrape: 'true'
    spec:
      serviceAccountName: nginx-ingress-serviceaccount
      nodeSelector:
        kubernetes.io/hostname: k8s-nginx-node0
      tolerations:
      - key: "app"
        operator: "Equal"
        value: "nginx-ingress-controller"
        effect: "NoSchedule"
      containers:
        - name: nginx-ingress-controller
          image: quay.io/kubernetes-ingress-controller/nginx-ingress-controller:0.13.0
          volumeMounts:
            - name: log-storage
              mountPath: /var/log/nginx/
          args:
            - /nginx-ingress-controller
            - --default-backend-service=$(POD_NAMESPACE)/nginx-ingress-controller
            - --configmap=$(POD_NAMESPACE)/nginx-configuration
            - --annotations-prefix=nginx.ingress.kubernetes.io
          env:
            - name: POD_NAME
              valueFrom:
                fieldRef:
                  fieldPath: metadata.name
            - name: POD_NAMESPACE
              valueFrom:
                fieldRef:
                  fieldPath: metadata.namespace
          resources:
            limits:
              memory: "2000Mi"
              cpu: 2
            requests:
              memory: "2000Mi"
              cpu: 2
          ports:
          - name: http
            containerPort: 80
            hostPort: 80
          - name: https
            containerPort: 443
            hostPort: 443
          livenessProbe:
            failureThreshold: 3
            httpGet:
              path: /healthz
              port: 10254
              scheme: HTTP
            initialDelaySeconds: 10
            periodSeconds: 10
            successThreshold: 1
            timeoutSeconds: 1
          readinessProbe:
            failureThreshold: 3
            httpGet:
              path: /healthz
              port: 10254
              scheme: HTTP
            periodSeconds: 10
            successThreshold: 1
            timeoutSeconds: 1
      volumes:
      - name: log-storage
        hostPath:
          path: /data/logs/nginx/
-- lephix
kubernetes

1 Answer

4/23/2018

Thanks @ewramner

setDebugging is very useful and saved my days.

According to my deployment object, the apiVersion: extensions/v1beta1 is too old. change to apiVersion: apps/v1beta2 solved the problem.

-- lephix
Source: StackOverflow