Creating Deployment object to a service for AKS using kubectl runs throws server reported 400 issue

10/14/2019

While creating a deployment object in object and an associated ReplicaSet object. The ReplicaSet has two Pods, each of which runs the akswebapp application. It throws the below exception.

error: unable to read URL "https://mystorage12111.file.core.windows.net/aksfiles/akswebapp-application.yaml", server reported 400 The value for one of the HTTP headers is not in the correct format., status code=400

Yaml file:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: docker-webapp
spec:
  selector:
    matchLabels:
      run: load-balancer-example
  replicas: 2
  template:
    metadata:
      labels:
        run: load-balancer-example
    spec:
      containers:
        - name: docker-webapp
          image: dockerwebapp
          ports:
            - containerPort: 8080
              protocol: TCP
-- user3214104
azure-aks
continuous-deployment
kubectl
kubernetes

1 Answer

10/18/2019

For your issue, the problem is that the labels' name and value in your deployment and the service. You need to make them the same both in the deployment and service. So the code in the YAML file should be like this:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: docker-webapp
spec:
  selector:
    matchLabels:
      run: load-balancer-example
  replicas: 2
  template:
    metadata:
      labels:
        run: load-balancer-example
    spec:
      containers:
        - name: docker-webapp
          image: dockerwebapp
          ports:
            - containerPort: 8080
              protocol: TCP
---
kind: Service
apiVersion: v1 
metadata: 
  name: dockerwebservice 
spec: 
  selector: 
    run: load-balancer-example
  ports: 
  - protocol: TCP 
    port: 80 
    targetPort: 80 
  type: LoadBalancer
-- Charles Xu
Source: StackOverflow