<p>I've got familiar with kubernetes very recently. I want to deploy a project into my minikube cluster. Here is the yaml file:</p>
<p><em>deployment.yml</em></p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    run: project
  name: project
  namespace: default
spec:
  replicas: 1
  selector:
    matchLabels:
      run: project
  template:
    metadata:
      labels:
        run: project
    spec:
      hostNetwork: true
      containers:
      - name: container1
        image: image1
        imagePullPolicy: Never
      - name: container2
        image: image2
        imagePullPolicy: Never
</code></pre>
<p>I created the deployment successfully, and both containers in a pod are up and running but these containers can not connect to local resources like databases(e.g. redis)</p>
<p>I get logs via this command and the resut is as below.</p>
<p>kubectl logs -f project-5f5c6df6bc-q82s5 container1</p>
<blockquote>
<p><em>Error 111 connecting to 127.0.0.1:6379. Connection refused.</em></p>
</blockquote>

Zar Ashouri
<p>I think you can use a Service of type <code>ExternalName</code> with the special hostname provided by Minikube:
<a href="https://minikube.sigs.k8s.io/docs/handbook/host-access/#hostminikubeinternal" rel="nofollow noreferrer">https://minikube.sigs.k8s.io/docs/handbook/host-access/#hostminikubeinternal</a>
This exposes an external Service that can be consumed from Kubernetes.</p>
<pre><code>kind: Service
apiVersion: v1
metadata:
  name: redis
spec:
  type: ExternalName
  externalName: host.minikube.internal
</code></pre>
<p>In the code that runs in the cluster simply use the host <code>redis</code> so that Kubernetes can retrieve the mapping to the desired host.</p>
