I have an application running on a pure docker environment. I wanted to deploy that in a k8s. Hence I created config maps, deployments etc. Below is the config file before deploying to k8s.
config:
message:
- type: "fusion:expense:expense_type:v1"
versions:
- version: "v1"
handler:
request_uri: "http://localhost:8082/api/v1/expenses/"
- version: "v2"
handler:
request_uri: "http://localhost:8082/api/v2/expenses/"
- type: "card_type"
versions:
- version: "v1"
handler:
request_uri: "http://localhost:8082/api/v1/cardtype"
ossprovider:
endpoint: "http://localhost:19000"
adaptors:
endpoint: http://localhost:8092/adaptors/
I created a service like
kind: Service
metadata:
name: fin-service
spec:
type: ClusterIP
ports:
- port: 8090
targetPort: 8090
protocol: TCP
name: http
- port: 8082
targetPort: 8082
protocol: TCP
- port: 19000
targetPort: 19000
protocol: TCP
selector:
fin-app
My deployment looks like this:
apiVersion: apps/v1
kind: Deployment
metadata:
name: fin
namespace: {{ .Values.namespace }}
labels:
fin
spec:
replicas: {{ .Values.replicaCount }}
selector:
matchLabels:
fin
template:
metadata:
labels:
fin
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
containers:
- name: {{ .Values.containers.oss_messaginglayer.name }}
image: {{ .Values.image.oss_messaginglayer.repository }}
imagePullPolicy: {{ .Values.image.pullPolicy }}
ports:
- name: http
containerPort: 8090
protocol: TCP
Since I created a service, I wanted to use this service end point in the config file as fin-service instead of localhost.
app:
config:
message:
- type: "fusion:expense:expense_type:v1"
versions:
- version: "v1"
handler:
request_uri: "http://fin-service:8082/api/v1/expenses/"
- version: "v2"
handler:
request_uri: "http://fin-service:8082/api/v2/expenses/"
- type: "card_type"
versions:
- version: "v1"
handler:
request_uri: "http://fin-service:8082/api/v1/cardtype"
ossprovider:
endpoint: "http://fin-service:19000"
adaptors:
endpoint: http://fin-service:8092/adaptors/
But I get connection refused errors at http://fin-service:19000. Where am I going off the track?
It looks like your Service is being created in the default
namespace, since you're not providing a metadata.namespace
value explicitly. On the other hand, your deployment is specifying metadata.namespace
to be {{ .Values.namespace }}
(looks like you're using Helm).
You have a couple options:
{{ .Values.namespace }}
, in which case you can continue using fin-service
to reference the service in your config, orfin-service.default
, since <service-name>.<namespace>
will also resolve to your service. You'll also need to make sure your Deployment is running in the default
namespace or else your service pod selector won't find any of the deployment pods.Check out the Kubernetes documentation on DNS for Services and Pods for more on how services and pods can be accessed within a cluster.