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.
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.
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).
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'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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With