<p>I have a bare-metal kubernetes (<code>v1.11.0</code>) cluster created with kubeadm and working fine without any issues. Network with calico and made it a single node cluster using kubectl taint nodes command. (single node is a requirement).</p>
<p>I need to run mydockerhub/sampleweb static website image on host port 80. Assume the IP address of the ubuntu server running this kubernetes is 192.168.8.10.</p>
<p>How to make my static website available on <code>192.168.8.10:80</code> or a hostname mapped to it on local DNS server? (Example: <code>frontend.sampleweb.local:80</code>). Later I need to run other services on different port mapped to another subdomain. (Example: <code>backend.sampleweb.local:80</code> which routes to a service run on port 8080).</p>
<p>I need to know:</p>
<ol>
<li><p>Can I achieve this without a load balancer?</p>
</li>
<li><p>What resources needed to create? (ingress, deployment, etc)</p>
</li>
<li><p>What additional configurations needed on the cluster? (network policy, etc)</p>
<p>Much appreciated if sample yaml files are provided.</p>
</li>
</ol>
<p>I'm new to kubernetes world. I got sample kubernetes deployments (like <a href="https://github.com/microservices-demo/microservices-demo" rel="noreferrer">sock-shop</a>) working end-to-end without any issues. I tried NodePort to access the service but instead of running it on a different port I need to run it exact port 80 on the host. I tried many ingress solutions but didn't work.</p>
<p>Screenshot of my setup:<br />
<a href="https://i.stack.imgur.com/G1yJq.png" rel="noreferrer"><img src="https://i.stack.imgur.com/G1yJq.png" alt="enter image description here" /></a></p>

<p>I recently used <a href="https://traefik.io/" rel="noreferrer">traefik.io</a> to configure a project with similar requirements to yours.</p>

<p>So I'll show a basic solution with <code>traefik</code> and ingresses.</p>

<p>I dedicated a whole namespace (you can use <code>kube-system</code>), called <code>traefik</code>, and created a kubernetes serviceAccount:</p>

<pre><code>apiVersion: v1
kind: Namespace
metadata:
  name: traefik
---
apiVersion: v1
kind: ServiceAccount
metadata:
  namespace: traefik
  name: traefik-ingress-controller
</code></pre>

<p>The traefik controller which is invoked by ingress rules requires a ClusterRole and its binding:</p>

<pre><code>---
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRole
metadata:
  name: traefik-ingress-controller
rules:
  - apiGroups:
      - ""
    resources:
      - services
      - endpoints
      - secrets
    verbs:
      - get
      - list
      - watch
  - apiGroups:
      - extensions
    resources:
      - ingresses
    verbs:
      - get
      - list
      - watch
---
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
  name: traefik-ingress-controller
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: traefik-ingress-controller
subjects:
- kind: ServiceAccount
  namespace: traefik
  name: traefik-ingress-controller
</code></pre>

<p>The traefin controller will be deployed as daemonset (i.e. by definition one for each node in your cluster) and a Kubernetes service is dedicated to the controller:</p>

<pre><code>kind: DaemonSet
apiVersion: extensions/v1beta1
metadata:
  name: traefik-ingress-controller
  namespace: traefik
  labels:
    k8s-app: traefik-ingress-lb
spec:
  template:
    metadata:
      labels:
        k8s-app: traefik-ingress-lb
        name: traefik-ingress-lb
    spec:
      serviceAccountName: traefik-ingress-controller
      terminationGracePeriodSeconds: 60
      containers:
      - name: traefik-ingress-lb
        image: traefik
        ports:
        - name: http
          containerPort: 80
          hostPort: 80
        - name: admin
          containerPort: 8080
        securityContext:
          capabilities:
            drop:
            - ALL
            add:
            - NET_BIND_SERVICE
        args:
        - --api
        - --kubernetes
        - --logLevel=INFO
---
kind: Service
apiVersion: v1
metadata:
  namespace: traefik
  name: traefik-ingress-service
spec:
  selector:
    k8s-app: traefik-ingress-lb
  ports:
    - protocol: TCP
      port: 80
      name: web
    - protocol: TCP
      port: 8080
      name: admin
</code></pre>

<p>The final part requires you to create a service for each microservice in you project, here an example:</p>

<pre><code>apiVersion: v1
kind: Service
metadata:
  namespace: traefik
  name: my-svc-1
spec:
  selector:
    k8s-app: traefik-ingress-lb
  ports:
  - port: 80 
    targetPort: 8080
</code></pre>

<p>and also the ingress (set of rules) that will forward the request to the proper service:</p>

<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  namespace: traefik
  name: ingress-ms-1
  annotations:
    kubernetes.io/ingress.class: traefik
spec:
  rules:
  - host: my-address-url
    http:
      paths:
      - backend:
          serviceName: my-svc-1
          servicePort: 80
</code></pre>

<p>In this ingress I wrote a host URL, this will be the entry point in your cluster, so you need to resolve the name to your master K8S node. If you have more nodes which could be master, then a loadbalancer is suggested (in this case the host URL will be the LB).</p>

<p>Take a look to <a href="https://kubernetes.io/" rel="noreferrer">kubernetes.io</a> documentation to have clear the concepts for kubernetes. Also <a href="https://traefik.io/" rel="noreferrer">traefik.io</a> is useful.</p>

<p>I hope this helps you.</p>
