Issue
i have a question about kubernetes networking.
My working senario:
- I have a Jenkins container my localhost and this container up and running. Inside Jenkins, i have a job. Access jenkins , i use "http://localhost:8080" url. (jenkins is not runing inside kubernetes)
- My flask app, trigger the Jenkins job with this command:
@app.route("/create",methods=["GET","POST"]) def create(): if request.method =="POST": dosya_adi=request.form["sendmail"] server = jenkins.Jenkins('http://localhost:8080/', username='my-user-name', password='my-password') server.build_job('jenkins_openvpn', {'FILE_NAME': dosya_adi}, token='my-token')
- Then, i did Dockerize this flask app. My image name is: "jenkins-app"
- If i run this command, everythings perfect:
docker run -it --network="host" --name=jenkins-app jenkins-app
But i want to do samething with kubernetes. For that i wrote this yml file.
apiVersion: v1
kind: Pod
metadata:
name: jenkins-pod
spec:
hostNetwork: true
containers:
- name: jenkins-app
image: jenkins-app:latest
imagePullPolicy: Never
ports:
- containerPort: 5000
- With this yml file, i access the flask app using port 5000. While i want to trigger jenkins job, i get an error like this: requests.exceptions.ConnectionError
Would you suggest if there is a way to do this with Kubernetes?
Solution
I create an endpoint.yml file and add in this file below commands, this solve my problem:
apiVersion: v1
kind: Endpoints
metadata:
name: jenkins-server
subsets:
- addresses:
- ip: my-ps-ip
ports:
- port: 8080
Then, I change this line in my flask app like this:
server = jenkins.Jenkins('http://my-ps-ip:8080/', username='my-user-name', password='my-password')
Answered By - ennur