pod inter connections inside k8s cluster

22 views
Skip to first unread message

Tristan FAURE

unread,
Sep 17, 2018, 11:29:33 AM9/17/18
to Jenkins Users
Hello,
I need your advice, i want to achieve integration tests using several pods :

pod 1 : database postgresql
pod 2 : build with maven image and test using a connection to pod 2

To implement that I wanted to use IP address (with ip.namespace.pod.cluster.local) of pod1, but I don't know if it is the recommended way, and if it is i don't know how to get this IP address

I have seen that I can have my pod agent name using env JENKINS_AGENT_NAME but I don't know what is the best to share it from stages of pod1 in env of pod2

Thank you in advance

Tristan FAURE

JonathanRRogers

unread,
Sep 17, 2018, 9:56:53 PM9/17/18
to Jenkins Users
This is more of a Kubernetes question than a Jenkins one. I am running Jenkins inside a K8S cluster and I'm not aware of anything Jenkins-specific that will do what you want. I use K8S clients including kubectl and the Python "kubernetes" package to query and manipulate objects directly. I run Postgres as a statefulset with a service so that any Jenkins slave running in the same K8S namespace can connect to it using the service name as hostname. Jenkins can run any external command you want, so which client executable or library makes the most sense depends on your experience and what you're trying to accomplish.

Carlos Sanchez

unread,
Sep 17, 2018, 10:48:14 PM9/17/18
to jenkins...@googlegroups.com
You need to use services if you want to expose pods
If you put everything in one pod, you can use localhost to talk between containers

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/21112f04-0cbc-4680-b763-102dfd030dca%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jonathan Rogers

unread,
Sep 17, 2018, 11:01:47 PM9/17/18
to jenkins...@googlegroups.com
On 9/17/18 10:47 PM, Carlos Sanchez wrote:
> You need to use services if you want to expose pods
> If you put everything in one pod, you can use localhost to talk between
> containers

I'm not sure if you meant to respond to me or to Tristan FAURE. I would
also recommend using a service to allow processes in one pod to connect
to a server in another. However, as Tristan implies, defining a service
isn't strictly necessary. For example, to determine the IP address for a
pod if you know its name is "thingy", you could use a command like:

kubectl get pod thingy -o=jsonpath='{.status.podIP}'

--
Jonathan Rogers

Tristan FAURE

unread,
Sep 18, 2018, 1:10:16 AM9/18/18
to jenkins...@googlegroups.com
Thank you to both of you for your answers. I was thinking about creating services but my db is created then deleted during the build I was not sure it was a good practice (and if it is possible) to create dynamically (and delete then) a service directly from the jenkinsfile yaml. 

I will try

Regards (and good Jenkins world for people attending it !)



--
You received this message because you are subscribed to a topic in the Google Groups "Jenkins Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jenkinsci-users/6nYxOrwZ5LQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/0ca2a728-8055-8fca-9825-d8070f153cab%40gmail.com.

Tristan FAURE

unread,
Sep 18, 2018, 9:12:29 AM9/18/18
to jenkins...@googlegroups.com
Hello all my previous message with edit :
Thank you to both of you for your answers. I was thinking about creating services but my db is created then deleted during the build I was not sure it was a good practice (and if it is possible) to create dynamically (and delete then) a service directly from the jenkinsfile yaml. 

I will try
EDIT : I did not find how to declare the service in the yaml in my jenkinsfile (syntax error). All the containers in one pod works but I have resource limitations and I would prefer having them separated

Regards (and good Jenkins world for people attending it !)

Jonathan Rogers

unread,
Sep 18, 2018, 4:25:28 PM9/18/18
to jenkins...@googlegroups.com
On 9/18/18 9:12 AM, Tristan FAURE wrote:
> Hello all my previous message with edit :
> Thank you to both of you for your answers. I was thinking about creating
> services but my db is created then deleted during the build I was not
> sure it was a good practice (and if it is possible) to create
> dynamically (and delete then) a service directly from the jenkinsfile yaml. 
>
> I will try
> *EDIT : I did not find how to declare the service in the yaml in my
> jenkinsfile (syntax error). All the containers in one pod works but I
> have resource limitations and I would prefer having them separated*

I don't think you've said so, but I assume you're using the Jenkins
plugin called simply "kubernetes", which is documented at:

https://github.com/jenkinsci/kubernetes-plugin/blob/master/README.md

AFAICT, that plugin has no built-in way to create Kubernetes service
objects. This is why I recommended using kubectl, which allows to
create, delete and query any Kubernetes object. You will need to make
sure the Docker container image contains a kubectl binary of a version
appropriate for your Kubernetes cluster. You will also need to make sure
that kubectl can authenticate itself. I haven't tried it, but the
"Kubernetes CLI Plugin" may be a good option:

https://wiki.jenkins.io/display/JENKINS/Kubernetes+CLI+Plugin

--
Jonathan Rogers

Tristan FAURE

unread,
Sep 19, 2018, 2:22:51 AM9/19/18
to jenkins...@googlegroups.com
thank you for your answer, You were right about the plugin I used (ttps://github.com/jenkinsci/kubernetes-plugin/blob/master/README.md), sorry to not mention that

I will test the kubernetes cli plugin, but I think I will see the option with multi container in a pod because I would prefer my CI users don't use kubectl (it is already a problem for them to write pod yaml 😐)

--
You received this message because you are subscribed to a topic in the Google Groups "Jenkins Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jenkinsci-users/6nYxOrwZ5LQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jenkinsci-use...@googlegroups.com.

Vincent Latombe

unread,
Sep 19, 2018, 10:07:24 AM9/19/18
to Jenkins Users
Why do you use 2 different pods? Would be much simpler with a single one.

Vincent


You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/CA%2BtQ8YMO6r3RSDtkmMhR%2BOyvXNJaima-qqgtvBcDGxVezN4iwA%40mail.gmail.com.

Tristan FAURE

unread,
Sep 19, 2018, 10:23:02 AM9/19/18
to jenkins...@googlegroups.com
I do agree with you
but as I said my IT team wants to deploy small nodes on the cluster and sometimes my pods are too big and cannot be deployed, that's why I wanted to test separate pods.

I looked for some links for my IT team but what are the recommendations for k8s cluster, several small machines or few big machines ?

Regards

Tristan FAURE

Reply all
Reply to author
Forward
0 new messages