Change the port of Knative Service

mukundjalan created this issue on 2021-10-22 · The issue is replied 3 times

I have been trying to change the port of the "Service" object created by Knative but I do not see any option in the specifications to do so.

I am able to change the container port but that is not what I am trying to achieve. I need the service to listen on a different port (9080 in my case) from another service in the cluster or from outside the cluster.

Why is this required:
I am trying to create a POC with Istio & Knative in an EKS cluster owned by me. For this I was trying to convert the sample application "bookinfo" provided by istio from a generic k8s configuration to a knative service configuration. The microservices have a hardcoded 9080 port to communicate amongst each other as here. I was wondering that if we upgrade an existing system, we might have to face similar challenge as we may or may not have the liberty to update ports of the services that we are communicating within.

The original configuration for bookinfo application is available here
The modified k8s configuration of bookinfo application is as below

##################################################################################################
# Details service
##################################################################################################
apiVersion: serving.knative.dev/v1
kind: Service
metadata:
  name: details
spec:
  template:
    metadata:
      labels:
        app: details
        version: v1
    spec:
      serviceAccountName: bookinfo-details
      containers:
      - name: details
        image: docker.io/istio/examples-bookinfo-details-v1:1.16.2
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 9080
        securityContext:
          runAsUser: 1000
---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: bookinfo-details
  labels:
    account: details
---
##################################################################################################
# Ratings service
##################################################################################################
apiVersion: serving.knative.dev/v1
kind: Service
metadata:
  name: ratings
spec:
  template:
    metadata:
      labels:
        app: ratings
        version: v1
    spec:
      serviceAccountName: bookinfo-ratings
      containers:
      - name: ratings
        image: docker.io/istio/examples-bookinfo-ratings-v1:1.16.2
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 9080
        securityContext:
          runAsUser: 1000
---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: bookinfo-ratings
  labels:
    account: ratings
---
##################################################################################################
# Reviews service
##################################################################################################
apiVersion: serving.knative.dev/v1
kind: Service
metadata:
  name: reviews
spec:
  template:
    metadata:
      labels:
        app: reviews
        version: v2
    spec:
      serviceAccountName: bookinfo-reviews
      containers:
      - name: reviews
        image: docker.io/istio/examples-bookinfo-reviews-v2:1.16.2
        imagePullPolicy: IfNotPresent
        env:
        - name: LOG_DIR
          value: "/tmp/logs"
        ports:
        - containerPort: 9080
#        volumeMounts:
#        - name: tmp
#          mountPath: /tmp
#        - name: wlp-output
#          mountPath: /opt/ibm/wlp/output
        securityContext:
          runAsUser: 1000
#      volumes:
#      - name: wlp-output
#        emptyDir: {}
#      - name: tmp
#        emptyDir: {}
---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: bookinfo-reviews
  labels:
    account: reviews
---
##################################################################################################
# Productpage services
##################################################################################################
apiVersion: serving.knative.dev/v1
kind: Service
metadata:
  name: productpage
spec:
  template:
    metadata:
      labels:
        app: productpage
        version: v1
    spec:
      serviceAccountName: bookinfo-productpage
      containers:
      - name: productpage
        image: docker.io/istio/examples-bookinfo-productpage-v1:1.16.2
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 9080
#        volumeMounts:
#        - name: tmp
#          mountPath: /tmp
        securityContext:
          runAsUser: 1000
#      volumes:
#      - name: tmp
#        emptyDir: {}
---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: bookinfo-productpage
  labels:
    account: productpage

References

snneji wrote this answer on 2021-11-04

@nak, would you be able to help with this?

nak3 wrote this answer on 2021-11-06

Hi @mukundjalan

Please allow me to confirm which "Service" pod you would like to change:
For example, when we deployed hello-example ksvc, Knative creates the following ksvc and k8s services.

$ kubectl get ksvc
NAME            URL                                        LATESTCREATED         LATESTREADY           READY   REASON
hello-example   http://hello-example.default.example.com   hello-example-00001   hello-example-00001   True

$ kubectl get svc
NAME                          TYPE           CLUSTER-IP     EXTERNAL-IP                                            PORT(S)                                      AGE
hello-example                 ExternalName   <none>         knative-local-gateway.istio-system.svc.cluster.local   80/TCP                                       10s
hello-example-00001           ClusterIP      10.96.130.57   <none>                                                 80/TCP                                       59s
hello-example-00001-private   ClusterIP      10.96.101.65   <none>                                                 80/TCP,9090/TCP,9091/TCP,8022/TCP,8012/TCP   59s

Could you please point out what port you want to change to?

mukundjalan wrote this answer on 2021-11-23

Hi @nak3,

Here I would like to change the port of "hello-example" service to some value other than 80, lets say 9080. How can I achieve this?

🤔
Didn't find what you were looking for ?
Create your own issue
More Details About Repo
Owner Name knative
Repo Name docs
Full Name knative/docs
Language HTML
Created Date 2018-06-21
Updated Date 2022-01-17
Star Count 3155
Watcher Count 103
Fork Count 1003
Issue Count 73

YOU MAY BE INTERESTED

Issue Title State Comments Created Date Updated Date Closed Date