AKS Nginx controller tcp port

89 views Asked by At

I have 1 AKS clusters with multiple services and 1 ingress controller

I have a requirement for 1 of the service to listen to tcp on port 11112

Below is my deployment file

apiVersion: apps/v1
kind: Deployment
metadata:
  creationTimestamp: null
  labels:
    app: xxx-py
  name: xxx-py
spec:
  replicas: 2
  selector:
    matchLabels:
      app: xxx-py
  strategy: {}
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: xxx-py
    spec:
      containers:
      - image: prodacr01.azurecr.io/xxxpy:#{Build.BuildId}#
        name: xxx-py
        imagePullPolicy: Always
        resources: {}
        ports:
          - containerPort: 8000
          - containerPort: 11112
      imagePullSecrets:
        - name: regcred
status: {}

---

apiVersion: v1
kind: Service
metadata:
  name: xxx-py
  labels:
    run: xxx-py
spec:
  ports:
  - name: httpapp
    protocol: TCP
    port: 80
    targetPort: 8000
  - name: dapp
    protocol: TCP
    port: 11112
    targetPort: 11112
  selector:
    app: xxx-py

What changes are required to make it accessible on 11112?

1

There are 1 answers

0
Komali Annem On

I have created the different deployments to expose the service to port 11112

I have created the sample nginx deployment file

 apiVersion: apps/v1
 kind: Deployment
 metadata:
     name: my-deployment
  spec:  
    selector: 
       matchLabels:
             app: APPXXX  
             department: XXXX  
         replicas: 3  
         template: 
            metadata:
                labels:   
                    app: appXXX     
                    department: XXXX 
             spec:   
                containers:  
                - name: hello  
                   image: "IMAGEXXX

Created the deployment using below command

Kubectl apply -f filename.yaml

enter image description here

To check the deployment pod kubectl get pods

I have created the manifest file for service type of clusterIP

apiVersion: v1
kind: Service
metadata:
  name: my-cip-service
spec:
  type: ClusterIP  #Type of port(NODE/load balancer/cluster)  
  selector: 
    app: APPXXXX 
    department: XXXX
ports:
- protocol: TCP 
  port: 8000  
  targetPort: 11112

To deploy the file and check the services which we have created use the below commands

kubectl apply -f 
kubectl get svc

enter image description here

To view the service kubectl get service my-np-service --output yaml

If the nodes in the cluster have an external IP address use the below command

kubectl get nodes --output wide

We can check with the Loadbalancer/cluster/nodeport IP weather servoce are exposed to 11112 port ot not

IPaddress:11112

enter image description here

We can also use the below command to expose the service to 11112 port

kubectl expose deployment deployment_name --name service_name \
--type Cluster_IP --protocol TCP --port 80 --target-port 8080