14

I have a docker image from I am doing

docker run --name test -h test -p 9043:9043 -p 9443:9443 -d ibmcom/websphere-traditional:install

I am trying to put into a kubernetes deploy file and I have this:

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: websphere
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: websphere
    spec:
      containers:
      - name: websphere
        image: ibmcom/websphere-traditional:install
        ports:
        - containerPort: 9443
        resources:
          requests: 
            memory: 500Mi
            cpu: 0.5
          limits:
            memory: 500Mi
            cpu: 0.5
        imagePullPolicy: Always

my service.yaml

apiVersion: v1
kind: Service
metadata:
  name: websphere
  labels:
    app: websphere
spec:
  type: NodePort #Exposes the service as a node ports
  ports:
  - port: 9443
    protocol: TCP
    targetPort: 9443
  selector:
    app: websphere

May I have guidance on how to map 2 ports in my deployment file?

mohan08p
  • 5,002
  • 1
  • 28
  • 36
Adam
  • 1,157
  • 6
  • 19
  • 40

2 Answers2

15

You can add as many ports as you need.

Here your deployment.yml:

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: websphere
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: websphere
    spec:
      containers:
      - name: websphere
        image: ibmcom/websphere-traditional:install
        ports:
        - containerPort: 9043
        - containerPort: 9443
        resources:
          requests: 
            memory: 500Mi
            cpu: 0.5
          limits:
            memory: 500Mi
            cpu: 0.5
        imagePullPolicy: IfNotPresent

Here your service.yml:

apiVersion: v1
kind: Service
metadata:
  name: websphere
  labels:
    app: websphere
spec:
  type: NodePort #Exposes the service as a node ports
  ports:
  - port: 9043
    name: hello
    protocol: TCP
    targetPort: 9043
    nodePort: 30043
  - port: 9443
    name: privet
    protocol: TCP
    targetPort: 9443
    nodePort: 30443
  selector:
    app: websphere

Check on your kubernetes api-server configuration what is the range for nodePorts (usually 30000-32767, but it's configurable).

EDIT

If I remove from deployment.yml the resources section, it starts correctly (after about 5 mins). Here a snippet of the logs:

[9/10/18 8:08:06:004 UTC] 00000051 webcontainer I com.ibm.ws.webcontainer.VirtualHostImpl addWebApplication SRVE0250I: Web Module Default Web Application has been bound to default_host[:9080,:80,:9443,:506 0,:5061,:443].

Problems come connecting to it (I use ingress with traefik), because of certificates (I suppose):

[9/10/18 10:15:08:413 UTC] 000000a4 SSLHandshakeE E SSLC0008E: Unable to initialize SSL connection. Unauthorized access was denied or security settings have expired. Exception is javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?

To solve that (I didn't go further) this may help: SSLHandshakeE E SSLC0008E: Unable to initialize SSL connection. Unauthorized access was denied or security settings have expired

Trying to connect with port-forward:

enter image description here

and using dthe browser to connect, I land on this page:

enter image description here

Nicola Ben
  • 10,615
  • 8
  • 41
  • 65
  • Hi Nicola, I tried to do $ kubectl apply -f WB_Sphere_service.yml The Service "websphere" is invalid: * spec.ports[0].name: Required value * spec.ports[1].name: Required value – Adam Sep 09 '18 at 16:30
  • Thank you NIcola. I tried to do a port forward to my local host: kubectl port-forward websphere-7874884868-ntz54 9043:9043 9443:9443 but it told me that 043 -> 9043: error forwarding port 9043 to pod 7e184665bf11f95ee02d07d40224a52368aa6b50240f0c7faf1a335d5b87a86e, uid : exit status 1: 2018/09/09 16:49:06 socat[1668] E connect(5, AF=2 127.0.0.1:9043, 16): Connection refused – Adam Sep 09 '18 at 16:49
  • Does your image ibmcom/websphere-traditional open those port numbers? – Nicola Ben Sep 09 '18 at 16:51
  • yes based on documentation. docker run --name test -h test -p 9043:9043 -p 9443:9443 -d \ ibmcom/websphere-traditional:install – Adam Sep 09 '18 at 16:55
  • I added some info. – Nicola Ben Sep 10 '18 at 08:25
  • i got that too @nicola. But i tried to access the app and nothing happened . how did you access it? https://:30043/ibm/console/login.do?action=secure – Adam Sep 10 '18 at 11:04
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/179748/discussion-between-nicola-ben-and-adam). – Nicola Ben Sep 10 '18 at 13:09
3

Well in kubernetes you can define your ports using #port label. This label comes under ports configuration in your deployment. According to the configurations you can simply define any numbers of ports you wish. Following example shows how to define two ports.

apiVersion: v1
kind: Service
metadata:
  name: my-service
spec:
  selector:
    app: MyApp
  ports:
    - name: http
      protocol: TCP
      port: 80
      targetPort: 9376
    - name: https
      protocol: TCP
      port: 443
      targetPort: 9377
uvindu sri
  • 264
  • 1
  • 4
  • 16