How to specify/modiy target-port on a newly created app through openshift CLI? - openshift

I am trying to expose a new app created via openshift command line(oc). This is a nodeJS server listening on port=3000. However, opeshift defaults the target-port to 8080 as shown in the following service.yaml:
kind: Service
apiVersion: v1
.............
.............
spec:
ports:
- name: 8080-tcp
protocol: TCP
port: 8080
targetPort: 8080
.........
I want to be able to update targetPort via the command line. I already followed these steps, but no luck so far:
step1: oc new-project my-new-project
step2: oc new-app https:\\github.org.com\my-new-app.git
step3: oc expose service my-new-app --target-port=3000
Error: **cannot use --target-port with --generator=route/v1**
Note: I am able to access the app(i.e. port=3000) only when I manually update targetPort to 3000 in Services.yaml.

You didnt specify port . Try this.
oc expose service my-new-app --target-port=3000 --port=8080

Related

SRVE0255E: A WebGroup/Virtual Host to handle /ibm/console/ has not been defined

I have deployed WebSphere Traditional on RedHat OpenShift but I'm unable to get the admin console. I could see that the server is running inside the pod. Attaching the yaml files I have used and the pod logs that are generated. Please help. Thanks!
YAML Files for Pod and Service -
apiVersion: v1
kind: Pod
metadata:
name: was-traditional
labels:
app: websphere
spec:
containers:
- name: was-container
image: ibmcom/websphere-traditional:8.5.5.17
------------------------------------
apiVersion : v1
kind : Service
metadata :
name : was-service
spec :
selector :
app : websphere
type : NodePort
ports :
- protocol : TCP
port : 9043
targetPort : 9043
nodePort : 31085
WAS Pod Logs -
{"type":"was_message","host":"was-traditional","ibm_cellName":"DefaultCell01","ibm_nodeName":"DefaultNode01","ibm_serverName":"server1","ibm_sequence":"1611228360189_0000000000113","message":"SRVE0255E: A WebGroup\/Virtual Host to handle \/ibm\/console\/ has not been defined.","ibm_datetime":"2021-01-21T11:26:00.189+0000","ibm_messageId":"SRVE0255E","ibm_methodName":"handleRequest","ibm_className":"com.ibm.ws.webcontainer.internal.WebContainer","ibm_threadId":"0000006c","module":"com.ibm.ws.webcontainer.internal.WebContainer","loglevel":"SEVERE"}
You can oc port-forward <pod> 9043:9043 on a workstation that needs to view the admin console then access it via localhost:9043. It will not work with an alternate port due to how virtual hosting works in traditional websphere.

Windows Jenkins Slave unable to connect to master hosted on Openshift instance

Unable to connect jenkins master hosted On Openshift Cluster. Terminates with below error after handshaking:
may 23, 2020 2:05:55 PM hudson.remoting.jnlp.Main$CuiListener error
GRAVE: Failed to connect to jenkins-jnlp-poc:50000
java.io.IOException: Failed to connect to jenkins-jnlp-poc:50000
at org.jenkinsci.remoting.engine.JnlpAgentEndpoint.open(JnlpAgentEndpoint.java:246)
at hudson.remoting.Engine.connectTcp(Engine.java:678)
at hudson.remoting.Engine.innerRun(Engine.java:556)
at hudson.remoting.Engine.run(Engine.java:488)
Caused by: java.net.ConnectException: Connection timed out: connect
at sun.nio.ch.Net.connect0(Native Method)
at sun.nio.ch.Net.connect(Net.java:454)
at sun.nio.ch.Net.connect(Net.java:446)
at sun.nio.ch.SocketChannelImpl.connect(SocketChannelImpl.java:648)
at java.nio.channels.SocketChannel.open(SocketChannel.java:189)
at org.jenkinsci.remoting.engine.JnlpAgentEndpoint.open(JnlpAgentEndpoint.java:204)
... 3 more
I added route to jenkins-jnlp service but I'm not able to expose the port, I'been trying to configure nodePort but I couldn't archive it yet. Any help will be welcomed!
Thanks.
A Route will only work with HTTP / HTTPS traffic and will not work in this case and as you correctly noted, NodePorts is most likely what you want. Here is an example for a Service type NodePort using Port 32000:
apiVersion: v1
kind: Service
metadata:
name: jenkins-jnlp-poc-service
spec:
selector:
app: jenkins-jnlp-poc
type: NodePort
ports:
- name: jnlp
port: 50000
targetPort: 50000
nodePort: 32000
protocol: TCP
Note that you may need to change multiple parts of the Service:
The port and targetPort specifying which port the Service "listens" on and where traffic is forwarded to (typically to the port your container exposes)
The selector, which Pods are targeted (you'll need to check your Pods which labels are used and adjust accordingly)

How to put containers network to the kubernetes YAML file

For exmaple, I created network at docker
docker network create hello-rails
Then, I have mySQL, which is connected to this network
docker run -p 3306 -d --network=hello-rails --network-alias=db -e MYSQL_ROOT_PASSWORD=password --name hello-rails-db mysql
And also, I have rails server, which also rely on this network
docker run -it -p 3000:3000 --network=hello-rails -e MYSQL_USER=root -e MYSQL_PASSWORD=password -e MYSQL_HOST=db --name hello-rails benjamincaldwell/hello-docker-rails:latest
I want to write deployment on kubernetes for these two containers with YAML file. But I don't know, how to put network inside containers in the file. Do you have any recommendations?
In Kubernetes you would solve this by creating two services.
The MySQL service will look something like this:
kind: Service
apiVersion: v1
metadata:
name: mysql
spec:
selector:
app: mysql
ports:
- port: 3306
In your rails server, you can access the MySQL service by either using the mysql DNS name or using the MYSQL_SERVICE_HOST and MYSQL_SERVICE_PORT environment variables. There is no need to link the containers or specifying a network, as would be done in Docker.
Your Rails service will look like this:
kind: Service
apiVersion: v1
metadata:
name: rails
spec:
type: LoadBalancer
selector:
app: rails
ports:
- port: 3000
Notice the type: LoadBalancer, which specifies that this service will be published to the outside world. Depending on where you run Kubernetes, a public IP address will be automatically assigned to this service.
For more information, have a look at the Services documentation.

Change Deployment config from shell

I need to vary the deployment config of an application, by adding an extra YAML section within it (in the example the section name: ping and its two attributes)
containers:
- name: openshift-wf-cluster
image: 172.30.1.1:5000/demo/openshift-wf#sha256:5d7e13e981f25b8933d54c8716d169fadf1c4b9c03468a5b6a7170492d5b9d93
ports:
- containerPort: 8080
protocol: TCP
- name: ping
containerPort: 8888
protocol: TCP
Is it possible to do it from the oc shell command ?(without manually editing the file) A sort of adding an extra node to one section of the YAML ?
You can use the oc patch command to achieve this. See oc patch --help for more info. Try the following with your own deployment config name:
oc patch dc/YOURDC -p '[{"op": "replace", "path": "/spec/template/spec/containers/0/ports/1", "value":{"name":"ping","containerPort":8888,"protocol":"TCP"}}]' --type=json
Yes. You can edit your deployment config in place with the openshift tools
oc edit dc/deployment-1-name will open an editor for you to change your config.

openshiftv3 service url connection failed from within a project

I'm just starting to use OpenShift v3. I've been looking for examples on setting up a ci/cd pipeline using jenkins, nexus, sonarqube on openshift. I've found this nice example project but unfortunately I can't get it to work. The project can be found here: https://github.com/OpenShiftDemos/openshift-cd-demo
The problem I'm running into is that once a jenkins job is starting it will try to connect to the nexus service using this url: nexus:8081. This url is made up out of the openshift template by this section:
# Sonatype Nexus
- apiVersion: v1
kind: Service
metadata:
annotations:
description: Sonatype Nexus repository manager's http port
labels:
app: nexus
name: **nexus**
spec:
ports:
- name: web
port: **8081**
protocol: TCP
targetPort: 8081
selector:
app: nexus
deploymentconfig: nexus
sessionAffinity: None
type: ClusterIP
However it seems that jenkins (ran as a pod on openshift within the same project as nexus) can't connect to the url http://nexus:8081 and shows the following:
Connect to nexus:8081 [nexus/172.30.190.210] failed: Connection refused # line 81, column 25
any idea what is going on?