I have a minikube cluster with two pods (with ubuntu containers). What I need to do is route test traffic from one port to another through this minikube cluster. This traffic should be sent through these two pods like in the picture. I am a beginner in this Kubernetes stuff so I really don't know how to do this and which way to go... Please, help me or give me some hints.
I am working on ubuntu server ver. 18.04.
There are multiple options you can follow:
As you have two PODs you can expose one via service,
There is also a container to container communication possibility if you can run both applications in a single POD.
POD-1 to POD-2 communication you can use the service option or POD URI.
I agree with an answer provided by @Harsh Manvar and I would also like to expand a little bit on this topic.
There already is an answer with a similar setup. I encourage you to check it out:
There are different drivers that could be used to run your minikube
. They will have differences when it comes to dealing with inbound traffic. I missed the part that was telling about the driver used in the setup (comment). If it's the Docker
shown in the tags, you could follow below example.
Steps:
nginx-one
and nginx-two
Deployments
to imitate Pods
from the image nginx-one
to nginx-two
nginx-one
from LANnginx-one
and nginx-two
Deployments
to imitate Pods
from the imageYou can use following definitions to spawn two Deployments
where each one will have a single Pod
:
nginx-one.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-one
spec:
selector:
matchLabels:
app: nginx-one
replicas: 1
template:
metadata:
labels:
app: nginx-one
spec:
containers:
- name: nginx
image: nginx
ports:
- containerPort: 80
nginx-two.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-two
spec:
selector:
matchLabels:
app: nginx-two
replicas: 1
template:
metadata:
labels:
app: nginx-two
spec:
containers:
- name: nginx
image: nginx
ports:
- containerPort: 80
nginx-one
to nginx-two
You will need to use a Service to send the traffic from nginx-one
to nginx-two
. Example of such Service
could be following:
apiVersion: v1
kind: Service
metadata:
name: nginx-two-service
spec:
type: ClusterIP # could be changed to NodePort
selector:
app: nginx-two # IMPORTANT
ports:
- name: http
protocol: TCP
port: 80
targetPort: 80
After applying this definition you will be able to send the traffic to nginx-two
by using the service name (nginx-two-service
)
A side note!
You can use the IP of the
Pod
without theService
but this is not a recommended way.
nginx-one
from LANAssuming that you want to expose your minikube
instance to LAN with Docker
driver you will need to create a service and expose it. Example of such setup could be the following:
apiVersion: v1
kind: Service
metadata:
name: nginx-one-service
spec:
type: ClusterIP # could be changed to NodePort
selector:
app: nginx-one # IMPORTANT
ports:
- name: http
protocol: TCP
port: 80
targetPort: 80
You will also need to run:
$ kubectl port-forward --address 0.0.0.0 service/nginx-one-service 8000:80
Above command (ran on your minikube
host!) will expose your nginx-one-service
to be available on LAN. It will map port 8000 on the machine that ran this command to the port 80 of this service. You can check it by executing from another machine at LAN:
curl IP_ADDRESS_OF_MINIKUBE_HOST:8000
A side note!
You will need root access to have your inbound traffic enter on ports lesser than 1024.
You will need to check if there is a communication between the objects as shown in below "connection diagram".
PC
-> nginx-one
-> nginx-two
-> example.com
The testing methodology could be following:
PC
-> nginx-one
:
curl MINIKUBE_IP_ADDRESS:8000
nginx-one
-> nginx-two
:
nginx-one
Pod
and run command: $ kubectl exec -it NGINX_POD_ONE_NAME -- /bin/bash
$ curl nginx-two-service
nginx-two
-> example.com
:
nginx-two
Pod
and run command: $ kubectl exec -it NGINX_POD_TWO_NAME -- /bin/bash
$ curl example.com
If you completed above steps you can swap nginx
Pods
for your own software.
Additional notes and resources:
I encourage you to check kubeadm
as it's the tool to create your own Kubernetes clusters:
As you said:
I am a beginner in this Kubernetes stuff so I really don't know how to do this and which way to go... Please, help me or give me some hints.
You could check following links for more resources: