I have a Replication Controller which creates more than one PODs. Within each POD, there is a container running an application.
Now within the container, it can call kubernetes API as below.
KUBE_TOKEN=$(</var/run/secrets/kubernetes.io/serviceaccount/token)
curl --silent --insecure --header "Authorization: Bearer $KUBE_TOKEN" \
https://$KUBERNETES_SERVICE_HOST:$KUBERNETES_PORT_443_TCP_PORT/api/v1/namespaces/$POD_NAMESPACE/pods/$POD_NAME
POD_NAME
is the name of the POD;
POD_NAMESPACE
is the namespace of the POD
The application instances in contains make up a cluster. And they elect one of the application instances as master, the others are slaves which replicates the data from master in real-time. When the master instance fails, another slave instance will be promoted to master.
When the application in the container is promoted to master, I want the master application instance to call the kubernetes API so that all the traffic goes to this POD/container.
{
"kind": "Service",
"apiVersion": "v1",
"metadata": {
"name": "my-cluster"
},
"spec": {
"ports": [{
"port": 33379,
"targetPort": 33379
}],
"type" : "None",
"selector": {
"name": "<POD_NAME>"
}
}
}
I specified the POD_NAME
as the selector, but the service can not find any of the POD.
How can I configure the service so that all the traffic goes to that POD?