0

I have a kubernetes deployment file user.yaml -

apiVersion: apps/v1
kind: Deployment
metadata:
  name: user-deployment
  namespace: stage
spec:
  replicas: 1
  selector:
    matchLabels:
      app: user
  template:
    metadata:
      labels:
        app: user
      annotations:
        prometheus.io/scrape: 'true'
        prometheus.io/port: '9022'
    spec:
      nodeSelector:
        env: stage
      containers:
        - name: user
          image: <docker image path>
          imagePullPolicy: Always
          resources:
            limits:
              memory: "512Mi"
              cpu: "250m"
            requests:
              memory: "256Mi"
              cpu: "200m"
          ports:
            - containerPort: 8080
          env:
            - name: MODE
              value: "local"
            - name: PORT
              value: ":8080"
            - name: REDIS_HOST
              value: "xxx"
            - name: KAFKA_ENABLED
              value: "true"
            - name: BROKERS
              value: "xxx"
      imagePullSecrets:
        - name: regcred

---
apiVersion: v1
kind: Service
metadata:
  namespace: stage
  name: user
spec:
  selector:
    app: user
  ports:
    - protocol: TCP
      port: 8080
      targetPort: 8080

---
apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
  name: user
  namespace: stage
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: user-deployment
  minReplicas: 1
  maxReplicas: 10
  metrics:
    - type: Resource
      resource:
        name: cpu
        target:
          type: Utilization
          averageUtilization: 50
    - type: Resource
      resource:
        name: memory
        target:
          type: AverageValue
          averageValue: 300Mi

This deployment is already running with linkerd injected with command cat user.yaml | linkerd inject - | kubectl apply -f -

Now I wanted to add linkerd inject annotation (as mentioned here) and use command kubectl apply -f user.yaml just like I use for a deployment without linkerd injected.

However, with modified user.yaml (after adding linkerd.io/inject annotation in deployment) -

apiVersion: apps/v1
kind: Deployment
metadata:
  name: user-deployment
  namespace: stage
spec:
  replicas: 1
  selector:
    matchLabels:
      app: user
  template:
    metadata:
      labels:
        app: user
      annotations:
        prometheus.io/scrape: 'true'
        prometheus.io/port: '9022'
        linkerd.io/inject: enabled
    spec:
      nodeSelector:
        env: stage
      containers:
        - name: user
          image: <docker image path>
          imagePullPolicy: Always
          resources:
            limits:
              memory: "512Mi"
              cpu: "250m"
            requests:
              memory: "256Mi"
              cpu: "200m"
          ports:
            - containerPort: 8080
          env:
            - name: MODE
              value: "local"
            - name: PORT
              value: ":8080"
            - name: REDIS_HOST
              value: "xxx"
            - name: KAFKA_ENABLED
              value: "true"
            - name: BROKERS
              value: "xxx"
      imagePullSecrets:
        - name: regcred

---
apiVersion: v1
kind: Service
metadata:
  namespace: stage
  name: user
spec:
  selector:
    app: user
  ports:
    - protocol: TCP
      port: 8080
      targetPort: 8080

---
apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
  name: user
  namespace: stage
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: user-deployment
  minReplicas: 1
  maxReplicas: 10
  metrics:
    - type: Resource
      resource:
        name: cpu
        target:
          type: Utilization
          averageUtilization: 50
    - type: Resource
      resource:
        name: memory
        target:
          type: AverageValue
          averageValue: 300Mi

When I run kubectl apply -f user.yaml, it throws error -

service/user unchanged
horizontalpodautoscaler.autoscaling/user configured
Error from server (BadRequest): error when creating "user.yaml": Deployment in version "v1" cannot be handled as a Deployment: v1.Deployment.Spec: v1.DeploymentSpec.Template: v1.PodTemplateSpec.Spec: v1.PodSpec.Containers: []v1.Container: v1.Container.Env: []v1.EnvVar: v1.EnvVar.v1.EnvVar.Value: ReadString: expects " or n, but found 1, error found in #10 byte of ...|,"value":1},{"name":|..., bigger context ...|ue":":8080"}

Can anyone please point out where I have gone wrong in adding annotation?

Thanks

aquaman
  • 1,523
  • 5
  • 20
  • 39

1 Answers1

0

Try with double quotes like below

annotations:
        prometheus.io/scrape: "true"
        prometheus.io/port: "9022"
        linkerd.io/inject: enabled
Harsh Manvar
  • 27,020
  • 6
  • 48
  • 102