Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kubernetes service in HostAliases

Tags:

kubernetes

Is it possible to have a service name under hostAliases in Kubernetes? I want to point a non-existent domain name to a service instead of an IP.

Something like the following:

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: deployment-name
spec:
  replicas: 1
  template:
    spec:
      containers:
        hostAliases:
        - ip: "my-service-name"
          hostnames:
          - "my.domain.com"

If not, how would you guys set up a local hosts file entry for a pod to a service? I need to resolve the non-existent domain to the service.

like image 369
Neekoy Avatar asked Feb 14 '19 08:02

Neekoy


People also ask

What is Kubernetes service in simple words?

Kubernetes (also known as k8s or “kube”) is an open source container orchestration platform that automates many of the manual processes involved in deploying, managing, and scaling containerized applications.

What is a Kubernetes service used for?

A Kubernetes service is a logical abstraction for a deployed group of pods in a cluster (which all perform the same function). Since pods are ephemeral, a service enables a group of pods, which provide specific functions (web services, image processing, etc.) to be assigned a name and unique IP address (clusterIP).

How do I see what services are running in Kubernetes?

Using kubectl describe pods to check kube-system If the output from a specific pod is desired, run the command kubectl describe pod pod_name --namespace kube-system . The Status field should be "Running" - any other status will indicate issues with the environment.

What is the difference between Kubernetes pod and service?

What's the difference between a Service and a Deployment in Kubernetes? A deployment is responsible for keeping a set of pods running. A service is responsible for enabling network access to a set of pods. We could use a deployment without a service to keep a set of identical pods running in the Kubernetes cluster.


1 Answers

As @VKR explained in the other comment, HostAliases basically just injects into /etc/hosts which only allows for A-record type entries.

For CNAME entries, a workaround is to inject the alias into CoreDNS.

This can be done by editing the ConfirMap for CoreDNS:

$ kubectl edit configmap coredns -n kube-system

apiVersion: v1
data:
  Corefile: |
    .:53 {
        errors
        health
        rewrite name orderer0.example.com orderer0-example-com.orbix-mvp.svc.cluster.local
        rewrite name peer0.example.com peer0-example-com.orbix-mvp.svc.cluster.local
        kubernetes cluster.local {
          pods insecure
          upstream
          fallthrough in-addr.arpa ip6.arpa
        }
        prometheus :9153
        proxy . /etc/resolv.conf
        cache 30
    }

I've added the two lines that start with rewrite name and once CoreDNS is restarted, the new entries are available throughout the cluster.

CoreDNS can be restarted using the following command:

kubectl exec -n kube-system coredns-980047985-g2748 -- kill -SIGUSR1 1

The above needs to be ran for both of the CoreDNS pods.

like image 138
Neekoy Avatar answered Sep 20 '22 01:09

Neekoy