Home > Net >  How to update ingress controller with a new deployment
How to update ingress controller with a new deployment

Time:07-20

I am very new to azure kubernetes! Right now I am just playing around with it, trying to work out how to create things using kubectl. I already have my cluster set up, and I have created a couple of pods using an existing container in our registry. I also created an ingress controller using azure application gateway.

What I want to do next is use a deployment yaml file to add a new replicated set of pods to the cluster, with a different image in there, and add the new service endpoint to the ingress controller. Remember, I am very new to this, so I am not sure if this is what you should do, or if you should create the pods/service first and then change the ingress controller? Or if you should have a separate deployment yaml for the ingress and recreate it on its own?

Anyway, here is the deployment yaml file that I have. When I try and run it with :

kubectl apply -f deployment.yml

I just get the error :

error: error validating "deployment.yml": error validating data: invalid object to validate; if you choose to ignore these errors, turn validation off with --validate=false

So I guess my question is, am I doing this right? And if this is the way I should be adding to my cluster, any idea what is wrong with this yaml?

---
  apiVersion: apps/v1
  kind: Deployment
  metadata:
    name: new-kuber-endpoint
    namespace: kuber-ut
  spec:
    replicas: 2
    selector:
      matchLabels:
        app: new-kuber-endpoint
    template:
      metadata:
        labels:
          app: new-kuber-endpoint
      spec:
        nodeSelector:
          kubernetes.io/os: linux
        containers:
          - name: amica-endpoint
            image: mycontainerreg.azurecr.io/new-endpoint:20220707.1
            ports:
              - containerPort: 80
            resources:
              requests:
                cpu: '0'
                memory: '0'
              limits:
                cpu: '256'
                memory: 11400G
---
  apiVersion: v1
  kind: Service
  metadata:
    name: new-kuber-endpoint-service
    namespace: kuber-ut
  spec:
    type: LoadBalancer
    ports:
      - targetPort: 80
        name: port80
        port: 80
        protocol: TCP
    selector:
      app: new-kuber-endpoint
---
  apiVersion: networking.k8s.io/v1
  kind: Ingress
  metadata:
    name: kuberdevingress
    namespace: kuber-ut
    uid: d9d490f0-1d3a-4433-bb03-7f1ba0dc611f
    resourceVersion: '1490171'
    generation: 3
  spec:
    rules:
      - http:
          paths:
            - path: /old
              pathType: Prefix
              backend:
                service:
                  name: old-endpoint-service
                  port:
                    number: 80
            - path: /new
              pathType: Prefix
              backend:
                service:
                  name: new-kuber-endpoint-service
                  port:
                    number: 80
  status:
    loadBalancer:
      ingress:
        - ip: <IP goes here>

I copied the kuberdevingress section from the azure portal, so I am not confident that is how I would recreate that ingress?

CodePudding user response:

You can use the single YAML file and manage it as per the requirement of creating multiple files for different resources that are on you.

If you want to update the deployment you can simply update the YAML and run

kubectl apply -f <filename>.yaml 

Also, there is an issue with your YAML, you can separate the resource using the --- in YAML if you don't manage the three different files for deployment, service, and ingress

  apiVersion: apps/v1
  kind: Deployment
  metadata:
    name: new-kuber-endpoint
    namespace: kuber-test
  spec:
    replicas: 2
    selector:
      matchLabels:
        app: new-kuber-endpoint
    template:
      metadata:
        labels:
          app: new-kuber-endpoint
      spec:
        nodeSelector:
          kubernetes.io/os: linux
        containers:
          - name: new-endpoint
            image: mycontainerregistry.azurecr.io/new-endpoint:20220707.1
            ports:
              - containerPort: 80
            resources:
              requests:
                cpu: '0'
                memory: '0'
              limits:
                cpu: '256'
                memory: 11400G
---
  apiVersion: v1
  kind: Service
  metadata:
    name: new-kuber-endpoint-service
    namespace: kuber-test
  spec:
    type: LoadBalancer
    ports:
      - targetPort: 80
        name: port80
        port: 80
        protocol: TCP
    selector:
      app: new-kuber-endpoint
---
  apiVersion: v1
  kind: Ingress
  metadata:
    name: kuberdevingress
    namespace: kuber-test
    annotations:
      kubernetes.io/ingress.class: azure/application-gateway
  spec:
    rules:
      - http:
          paths:
            - path: /
              pathType: Prefix
              backend:
                service:
                  name: old-endpoint-service
                  port:
                    number: 80
            - path: /
              pathType: Prefix
              backend:
                service:
                  name: new-endpoint-service
                  port:
                    number: 80

You can now update any field in the above YAML and re-apply the changes again to the Kubernetes cluster, it will update the changes.

If it's in service it will update that, if it's in ingress it will update those changes accordingly.

If you want to change the docker image you can update the deployment image with a different docker tag it will fetch and deploy that version.

CodePudding user response:

The error you encountered

error: error validating "deployment.yml": error validating data: invalid object to validate; if you choose to ignore these errors, turn validation off with --validate=false

isn't complete, usually there are more details, but actually it just means your yaml file deployment.yaml has a syntax error.

  • Related