kubernetes create a service with domain at the end

4/24/2018

I created a gossip cluster in AWS using kops, which means my cluster name is ending with k8s.local (clusters.test.k8s.local to be exected ), All is working fine until I tried to create a deployment where the pod name needs to be with a domain at the end (api-manager.iot.test.co.nz).

I know that it is not authorized to create pods that are not standing in the requirements os this regex:

'[a-z]([-a-z0-9]*[a-z0-9])?'

Is there a way I can do that?

I tried adding hostname under template->spec but it has the same restrictions (the regex).

This is my deployment YAML file:

apiVersion: apps/v1beta1
kind: Deployment
metadata:
  labels:
  name: api-manager
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: api-manager
    spec:
      volumes:
       - name: api-manager-efs
         persistentVolumeClaim:
          claimName: pvc-apim
      containers:
      - image: api-manager:2.1.0
        name: api-manager.iot.test.co.nz
        ports:
        - name: porta 
          containerPort: 9763
        - name: portb
          containerPort: 9443         
        env:
        - name: SLEEP
          value: "30"

        volumeMounts:
        - name: api-manager-efs
          mountPath: /home/wso2carbon/wso2am-2.1.0/repository 
-- Shachar Hamuzim Rajuan
kubernetes

2 Answers

7/8/2018

after a lot of struggling, This is my solution:

https://kubernetes.io/blog/2017/04/configuring-private-dns-zones-upstream-nameservers-kubernetes/

1.) create a dnsmasq with this your domain configuration inside, you will have to attach a cluster IP which must be in the range of your k8s cluster that you use.

These are the yaml files I created for that:

apiVersion: v1
kind: ConfigMap
metadata:
  name: dnsmasq
  labels:
    app: dnsmasq
data:
  dnsmasq.conf: |+
    user=root
    #dnsmasq config, for a complete example, see:
    #  http://oss.segetech.com/intra/srv/dnsmasq.conf
    #log all dns queries
    log-queries
    #dont use hosts nameservers
    no-resolv
    #use google as default nameservers
    server=8.8.4.4
    server=8.8.8.8
    #serve all .company queries using a specific nameserver
    server=/company/10.0.0.1
    #explicitly define host-ip mappings
    address=/api-manager.iot.test.vector.co.nz/100.64.53.55

apiVersion: v1
kind: Service
metadata:
  labels:
    app: dnsmasq
  name: dnsstub
spec:
  type: "{{.Values.Service.serviceType}}"
  clusterIP: 100.68.140.187
  ports:
   - port: {{ .Values.Service.serviceports.port }}
     protocol: UDP
  selector:
    app: dnsmasq


---
apiVersion: apps/v1beta1
kind: Deployment
metadata:
  name: dnsmasq
spec:
  replicas: {{ .Values.Deployment.replicaCount }}
  template:
    metadata:
      labels:
        app: dnsmasq
    spec:
      containers:
      - name: dnsmasq
        image:  dnsmasq:1.0.2
        ports:
           - containerPort: {{ .Values.Deployment.ports.containerport }}
             protocol: UDP
        volumeMounts:
        - name: etc
          mountPath: /etc/dnsmasq.conf
          subPath: dnsmasq.conf
      imagePullSecrets:
        - name: mprestg-credentials
      volumes:
      - name: etc
        configMap:
          name: dnsmasq
      dnsPolicy: Default

2.) Create a kube-dns config-map with stubDomain:

apiVersion: v1
kind: ConfigMap
metadata:
  name: kube-dns
  namespace: kube-system
data:
  stubDomains: |
    {"iot.test.vector.co.nz": ["100.68.140.187"]}

3.) Add the static IP that we defined in our dns configuration to out service:

apiVersion: v1
kind: Service
metadata:
  name: api-manager
  labels:
    app: api-manager
    tier: apim
spec:
  ports:
  - port: 9763
    name: porta
    targetPort: 9763

  selector:
    app: api-manager
  type: LoadBalancer
  clusterIP: 100.64.53.55
-- Shachar Hamuzim Rajuan
Source: StackOverflow

4/24/2018

No, you cannot create that kind of labels by design.

From the design document:

rfc1035/rfc1123 label (DNS_LABEL): An alphanumeric (a-z, and 0-9) string, with a maximum length of 63 characters, with the '-' character allowed anywhere except the first or last character, suitable for use as a hostname or segment in a domain name.

Here is the current implementation:

const dns1035LabelFmt string = "[a-z]([-a-z0-9]*[a-z0-9])?"
const dns1035LabelErrMsg string = "a DNS-1035 label must consist of lower case alphanumeric characters or '-', start with an alphabetic character, and end with an alphanumeric character"
const DNS1035LabelMaxLength int = 63

var dns1035LabelRegexp = regexp.MustCompile("^" + dns1035LabelFmt + "
quot;
) // IsDNS1035Label tests for a string that conforms to the definition of a label in // DNS (RFC 1035). func IsDNS1035Label(value string) []string { var errs []string if len(value) > DNS1035LabelMaxLength { errs = append(errs, MaxLenError(DNS1035LabelMaxLength)) } if !dns1035LabelRegexp.MatchString(value) { errs = append(errs, RegexError(dns1035LabelErrMsg, dns1035LabelFmt, "my-name", "abc-123")) } return errs }
-- Anton Kostenko
Source: StackOverflow