0

I am using Azure devops for regulation CI/CD in my project , i have a kubernetes cluster running through aks(azure kubernetes service) , i have used azure repo and everything and , every required file(viz. azure-pipeline file and services and deployment) is auto generated and i haven't altered anything in it , it builds nicely , but it fails in the deployment phase , I encounter this error as shown below ,

Error:

/usr/bin/kubectl apply -f /home/vsts/work/_temp/bookstore_1570774284000,/home/vsts/work/_temp/bookstore_1570774284001 --namespace default
error when retrieving current configuration of:
Resource: "apps/v1beta1, Resource=deployments", GroupVersionKind: "apps/v1beta1, Kind=Deployment"
Name: "alesblaze/bookstore", Namespace: "default"
Object: &{map["apiVersion":"apps/v1beta1" "kind":"Deployment" "metadata":map["annotations":map["kubectl.kubernetes.io/last-applied-configuration":""] "name":"alesblaze/bookstore" "namespace":"default"] "spec":map["replicas":'\x01' "template":map["metadata":map["labels":map["app":"alesblaze/bookstore"]] "spec":map["containers":[map["image":"***/alesblaze/bookstore" "name":"alesblaze/bookstore" "ports":[map["containerPort":'\u1f90']]]] "imagePullSecrets":[map["name":"bookstoreappacrd0a8-auth"]]]]]]}
from server for: "/home/vsts/work/_temp/bookstore_1570774284000": invalid resource name "alesblaze/bookstore": [may not contain '/']
error when retrieving current configuration of:
Resource: "/v1, Resource=services", GroupVersionKind: "/v1, Kind=Service"
Name: "alesblaze/bookstore", Namespace: "default"
Object: &{map["apiVersion":"v1" "kind":"Service" "metadata":map["annotations":map["kubectl.kubernetes.io/last-applied-configuration":""] "name":"alesblaze/bookstore" "namespace":"default"] "spec":map["ports":[map["port":'\u1f90']] "selector":map["app":"alesblaze/bookstore"] "type":"LoadBalancer"]]}
from server for: "/home/vsts/work/_temp/bookstore_1570774284001": invalid resource name "alesblaze/bookstore": [may not contain '/']
##[error]error when retrieving current configuration of:
Resource: "apps/v1beta1, Resource=deployments", GroupVersionKind: "apps/v1beta1, Kind=Deployment"
Name: "alesblaze/bookstore", Namespace: "default"
Object: &{map["apiVersion":"apps/v1beta1" "kind":"Deployment" "metadata":map["annotations":map["kubectl.kubernetes.io/last-applied-configuration":""] "name":"alesblaze/bookstore" "namespace":"default"] "spec":map["replicas":'\x01' "template":map["metadata":map["labels":map["app":"alesblaze/bookstore"]] "spec":map["containers":[map["image":"***/alesblaze/bookstore" "name":"alesblaze/bookstore" "ports":[map["containerPort":'\u1f90']]]] "imagePullSecrets":[map["name":"bookstoreappacrd0a8-auth"]]]]]]}
from server for: "/home/vsts/work/_temp/bookstore_1570774284000": invalid resource name "alesblaze/bookstore": [may not contain '/']
error when retrieving current configuration of:
Resource: "/v1, Resource=services", GroupVersionKind: "/v1, Kind=Service"
Name: "alesblaze/bookstore", Namespace: "default"
Object: &{map["apiVersion":"v1" "kind":"Service" "metadata":map["annotations":map["kubectl.kubernetes.io/last-applied-configuration":""] "name":"alesblaze/bookstore" "namespace":"default"] "spec":map["ports":[map["port":'\u1f90']] "selector":map["app":"alesblaze/bookstore"] "type":"LoadBalancer"]]}
from server for: "/home/vsts/work/_temp/bookstore_1570774284001": invalid resource name "alesblaze/bookstore": [may not contain '/']
Finishing: Deploy to Kubernetes cluster

Edit :

Service.yaml

apiVersion: v1
kind: Service
metadata:
    name: alesblaze/bookstore
spec:
    type: LoadBalancer
    ports:
    - port: 8080 
    selector:
        app: alesblaze/bookstore

deployment.yaml

apiVersion : apps/v1beta1
kind: Deployment
metadata:
  name: alesblaze/bookstore 
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: alesblaze/bookstore 
    spec:
      containers:
        - name: alesblaze/bookstore 
          image: bookstoreappacr.azurecr.io/alesblaze/bookstore 
          ports:
          - containerPort: 8080

Kubernetes version : 1.13.10

2
  • Please provide your YAMLs and Kubernetes version. – PjoterS Oct 11 '19 at 12:49
  • there you go! @PjoterS – Arjun Sharma Oct 11 '19 at 22:37
0

You received this issue because your YAMLs have some syntax issues, mostly too much spaces (also if you will use TAB instead of spaces it will also generate YAML syntax issue). For example, instead of

metadata:
    name: alesblaze/bookstore

should be

metadata:
  name: alesblaze/bookstore

Sub-parameter should be on level of the third letter. You can base your YAMLs on Kubernetes doc. I will paste proper YAMLs below.
Before that you have to know why you cannot use "/" in some of your parameters.

Even if in YAML syntax is correct (you can validate your yamls here), there are other validations.

apiVersion : apps/v1beta1
kind: Deployment
metadata:
  name: alesblaze/bookstore

If you will create deployment with --dry-run flag which skip some validations, kubectl will crate this deployment.

--dry-run=false: If true, only print the object that would be sent, without sending it.

$ kubectl create deployment alesblaze/bookstore --image=nginx --dry-run
deployment.apps/alesblaze/bookstore created (dry run)

However, if you will want to use it without this flag with all validation you will receive error:

$ kubectl create deployment alesblaze/bookstore --image=nginx
The Deployment "alesblaze/bookstore" is invalid: 
* metadata.name: Invalid value: "alesblaze/bookstore": a DNS-1123 subdomain must consist of lower case alphanumeric characters, '-' or '.', and must start and end with an alphanumeric character (e.g. 'example.com', regex used for validation is '[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*')
* metadata.labels: Invalid value: "alesblaze/bookstore": a valid label must be an empty string or consist of alphanumeric characters, '-', '_' or '.', and must start and end with an alphanumeric character (e.g. 'MyValue',  or 'my_value',  or '12345', regex used for validation is '(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])?')
* spec.selector.matchLabels: Invalid value: "alesblaze/bookstore": a valid label must be an empty string or consist of alphanumeric characters, '-', '_' or '.', and must start and end with an alphanumeric character (e.g. 'MyValue',  or 'my_value',  or '12345', regex used for validation is '(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])?')
* spec.selector: Invalid value: v1.LabelSelector{MatchLabels:map[string]string{"app":"alesblaze/bookstore"}, MatchExpressions:[]v1.LabelSelectorRequirement(nil)}: invalid label selector

Means that deployment name, label, selectors in Kubernetes cannot contain "/" because it will not pass all validations. Your have received similar issue:

Object: &{map["apiVersion":"apps/v1beta1" "kind":"Deployment" "metadata":map["annotations":map["kubectl.kubernetes.io/last-applied-configuration":""] "name":"alesblaze/bookstore" "namespace":"default"] "spec":map["replicas":'\x01' "template":map["metadata":map["labels":map["app":"alesblaze/bookstore"]] "spec":map["containers":[map["image":"***/alesblaze/bookstore" "name":"alesblaze/bookstore" "ports":[map["containerPort":'\u1f90']]]] "imagePullSecrets":[map["name":"bookstoreappacrd0a8-auth"]]]]]]}
from server for: "/home/vsts/work/_temp/bookstore_1570774284000": invalid resource name "alesblaze/bookstore": [may not contain '/']

It is describe in docs about names.

By convention, the names of Kubernetes resources should be up to maximum length of 253 characters and consist of lower case alphanumeric characters, -, and ., but certain resources have more specific restrictions.

Others resources like image or apiVersion allow to use "/".

Below YAMLS which will allow you to create Deployment and Service (with proper spaces and allowed characters):

Deployment.yaml

apiVersion : apps/v1beta1
kind: Deployment
metadata:
  name: alesblaze-bookstore
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: alesblaze-bookstore
    spec:
      containers:
      - name: alesblaze-bookstore 
        image: bookstoreappacr.azurecr.io/alesblaze/bookstore 
        ports:
        - containerPort: 8080

Service.yaml

apiVersion: v1
kind: Service
metadata:
  name: alesblaze-bookstore
spec:
  selector:
    app: alesblaze-bookstore
  ports:
  - port: 8080 
  type: LoadBalancer

If it helped, please upvote/accept my answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.