Getting a validtion error when trying to apply a Yaml file in AKS

2/5/2019

I'm following along with this tutorial. I'm at the stage where I deploy using the command:

kubectl apply -f azure-vote-all-in-one-redis.yaml

The YAML file looks like this:

version: '3'
services:
  azure-vote-back:
    image: redis
    container_name: azure-vote-back
    ports:
        - "6379:6379"

  azure-vote-front:
    build: ./azure-vote
    image: azure-vote-front
    container_name: azure-vote-front
    environment:
      REDIS: azure-vote-back
    ports:
        - "8080:80"

However, I'm getting the error:

error validating data: [apiVersion not set, kind not set]; if you choose to ignore these errors, turn validation off with --validate=false

If I add an apiVersion and a Kind, like this:

apiVersion: v1
kind: Pod

Then I get the error:

error validating data: ValidationError(Pod): unknown field "services" in io.k8s.api.core.v1.Pod

Am I missing something here?

--
azure
azure-aks
azure-container-registry
azure-kubernetes
kubernetes

2 Answers

2/5/2019

It looks like you're trying to apply a Docker Swarm/Compose YAML file to your Kubernetes cluster. This will not work directly without a conversion.

Using a tool like Kompose to convert your Docker YAML into k8s YAML is a useful step into migrating from one to the other.

For more information see https://kubernetes.io/docs/tasks/configure-pod-container/translate-compose-kubernetes/

-- Paul Annetts
Source: StackOverflow

2/5/2019

so first of all, every yaml definition should follow AKMS spec: apiVersion, kind, metadata, spec. Also, you should avoid pod and use deployments. Because deployments handle pods on their own.

Here's a sample vote-back\front definition:

apiVersion: apps/v1beta1
kind: Deployment
metadata:
  name: azure-vote-back
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: azure-vote-back
    spec:
      containers:
      - name: azure-vote-back
        image: redis
        ports:
        - containerPort: 6379
          name: redis
---
apiVersion: v1
kind: Service
metadata:
  name: azure-vote-back
spec:
  ports:
  - port: 6379
  selector:
    app: azure-vote-back
---
apiVersion: apps/v1beta1
kind: Deployment
metadata:
  name: azure-vote-front
spec:
  replicas: 3
  strategy:
    rollingUpdate:
      maxSurge: 60%
      maxUnavailable: 60% 
  template:
    metadata:
      labels:
        app: azure-vote-front
    spec:
      containers:
      - name: azure-vote-front
        image: aksrg.azurecr.io/azure-vote-front:voting-dev
        ports:
        - containerPort: 80
        env:
        - name: REDIS
          value: "azure-vote-back"
        - name: MY_POD_NAMESPACE
          valueFrom: {fieldRef: {fieldPath: metadata.namespace}}
      imagePullSecrets:
      - name: k8s
---
apiVersion: v1
kind: Service
metadata:
  name: azure-vote-front
spec:
  type: LoadBalancer
  ports:
  - port: 80
  selector:
    app: azure-vote-front
-- 4c74356b41
Source: StackOverflow