Defining node names on the yaml files with Loadbalancer and ports in AKS cluster

sjegadeeswaran

Jeg

Posted on October 23, 2022

Defining node names on the yaml files with Loadbalancer and ports in AKS cluster

I have the three nodes on the AKS cluster configured and I have configured 2 namespaces configured in the AKS cluster.

Namespace commands:

kubectl create namespace namespace name
kubectl get namespaces
kubectl describe namespaces namespace name
kubectl delete namespaces namespace name

Yaml file: tomcat-test.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: tomcat-test-helloworld
  labels:
    app: tomcat-test-helloworld
spec:
  replicas: 1
  selector:
    matchLabels:
      app: tomcat-test-helloworld
  template:
    metadata:
      labels:
        app: tomcat-test-helloworld
    spec:
      nodeName: xxx
      containers:
      - name: tomcat-test-helloworld
        image: xxx.azurecr.io/test-helloworld:v1
        resources:
          limits:
            memory: "2Gi"
            cpu: "1200m"
        ports:
        - containerPort: 8080
      imagePullSecrets:
      - name: secret
---
apiVersion: v1
kind: Service
metadata:
    name: tomcat-test-helloworld
    annotations:
      service.beta.kubernetes.io/azure-load-balancer-internal: "true"
spec:
    type: LoadBalancer
    loadBalancerIP: xx.xx.xxx.xx
    ports:
    - port: 8080
      targetPort: 8080
    selector:
        app: tomcat-test-helloworld
Enter fullscreen mode Exit fullscreen mode

Yaml file: tomcat-sample.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: tomcat-sample-helloworld
  labels:
    app: tomcat-sample-helloworld
spec:
  replicas: 1
  selector:
    matchLabels:
      app: tomcat-sample-helloworld
  template:
    metadata:
      labels:
        app: tomcat-sample-helloworld
    spec:
      nodeName: xxx
      containers:
      - name: tomcat-sample-helloworld
        image: xxx.azurecr.io/sample-helloworld:v1
        resources:
          limits:
            memory: "2Gi"
            cpu: "1200m"
        ports:
        - containerPort: 8080
      imagePullSecrets:
      - name: secret
---
apiVersion: v1
kind: Service
metadata:
    name: tomcat-sample-helloworld
    annotations:
      service.beta.kubernetes.io/azure-load-balancer-internal: "true"
spec:
    type: LoadBalancer
    loadBalancerIP: xx.xx.xxx.xx
    ports:
    - port: 8081
      targetPort: 8080
    selector:
        app: tomcat-sample-helloworld


Enter fullscreen mode Exit fullscreen mode

Using nodename we can define from which node this is to be executed. Memory is defined. Secret is configured for pulling images. To use the private IP, annotation is used in the service type. Load balancer IP is defined.

kubectl apply -f tomcat-test.yaml -n namespace-name
kubectl apply -f tomcat-sample.yaml -n namespace-name

We cannot define same ports for the loadbalancers and that is the reason the port is modified as 8081 in tomcat-sample.yaml

Though you define two different application in two different namespaces with the same container port, the application depends on the image what you use and what load balancer port we define in the yaml script (specified as port under ports section in the service yaml). If load balancer port is 8080, then tomcat-test-helloworld is exposed and if load balancer port is 8081 then tomcat-sample-helloworld is exposed.

Example from ActiveMQ port issue:

Image description

There can be different applications running on different ports on same load balancer IP as configured. Node name is defined to make the deployment happen in the specified node.

To create secret:

kubectl --kubeconfig "config-file-path" create secret docker-registry secret --docker-server=xxx.azurecr.io --docker-username=xxx --docker-password=xxx -n namespace name
Enter fullscreen mode Exit fullscreen mode
💖 💪 🙅 🚩
sjegadeeswaran
Jeg

Posted on October 23, 2022

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related