So I got a running cluster on my server. The server is running ubuntu 18.06
. I set up the cluster using kubeadm
, kubectl
and kubelet
.
My goal in a nutshell: I want to reach the services with executing http://myserver.com/service
.
I am kinda lost with exposing the services to port 8080. The current structure is like this:
31001:SERVICE:8080 -> 8080:POD
So I need to redirect the requests incoming using http://myserver.com/service
to the kubernetes service
with port 31001.
Current situation: I can only access the cluster via server IP:6443. All pods, services and so forth are up and running.
So my question: how can I make the services more or less public available on port 8080?
As requested below:
Output of
kubectl get all --all-namespaces -o wide
NAMESPACE NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
default pod/articleservice-deployment-6d48989664-jbzs6 1/1 Running 0 5h56m 192.168.0.4 server.address.com <none> <none>
default pod/cartservice-deployment-6b844f45b8-jz45h 1/1 Running 0 5h56m 192.168.0.5 server.address.com <none> <none>
default pod/catalogservice-deployment-d4bd6984c-6qlqg 1/1 Running 0 5h56m 192.168.0.6 server.address.com <none> <none>
default pod/customerservice-deployment-7d6f77fdbb-p42xj 1/1 Running 0 5h56m 192.168.0.7 server.address.com <none> <none>
kube-system pod/calico-node-5rl9m 2/2 Running 0 5h58m 999.999.99.99 server.address.com <none> <none>
kube-system pod/coredns-86c58d9df4-h64fg 1/1 Running 0 6h10m 192.168.0.2 server.address.com <none> <none>
kube-system pod/coredns-86c58d9df4-pwfj4 1/1 Running 0 6h10m 192.168.0.3 server.address.com <none> <none>
kube-system pod/etcd-server.address.net 1/1 Running 0 6h9m 999.999.99.99 server.address.com <none> <none>
kube-system pod/kube-apiserver-server.address.net 1/1 Running 0 6h10m 999.999.99.99 server.address.com <none> <none>
kube-system pod/kube-controller-manager-server.address.net 1/1 Running 0 6h9m 999.999.99.99 server.address.com <none> <none>
kube-system pod/kube-proxy-xb2qc 1/1 Running 0 6h10m 999.999.99.99 server.address.com <none> <none>
kube-system pod/kube-scheduler-server.address.net 1/1 Running 0 6h9m 999.999.99.99 server.address.com <none> <none>
NAMESPACE NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR
default service/articleservice NodePort 10.97.125.155 <none> 31001:31001/TCP,5005:32001/TCP 5h57m app=articleservice
default service/cartservice NodePort 10.99.42.169 <none> 31002:31002/TCP,5005:32002/TCP 5h57m app=cartservice
default service/catalogservice NodePort 10.106.101.93 <none> 31003:31003/TCP,5005:32003/TCP 5h57m app=catalogservice
default service/customerservice NodePort 10.106.2.159 <none> 31004:31004/TCP,5005:32004/TCP 5h57m app=customerservice
default service/kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 6h11m <none>
kube-system service/calico-typha ClusterIP 10.96.242.31 <none> 5473/TCP 5h58m k8s-app=calico-typha
kube-system service/kube-dns ClusterIP 10.96.0.10 <none> 53/UDP,53/TCP 6h11m k8s-app=kube-dns
NAMESPACE NAME DESIRED CURRENT READY UP-TO-DATE AVAILABLE NODE SELECTOR AGE CONTAINERS IMAGES SELECTOR
kube-system daemonset.apps/calico-node 1 1 1 1 1 beta.kubernetes.io/os=linux 5h58m calico-node,install-cni quay.io/calico/node:v3.3.2,quay.io/calico/cni:v3.3.2 k8s-app=calico-node
kube-system daemonset.apps/kube-proxy 1 1 1 1 1 <none> 6h11m kube-proxy k8s.gcr.io/kube-proxy:v1.13.1 k8s-app=kube-proxy
NAMESPACE NAME READY UP-TO-DATE AVAILABLE AGE CONTAINERS IMAGES SELECTOR
default deployment.apps/articleservice-deployment 1/1 1 1 5h56m articleservice elps/articleservice:1.0.7 app=articleservice
default deployment.apps/cartservice-deployment 1/1 1 1 5h56m cartservice elps/cartservice:1.0.7 app=cartservice
default deployment.apps/catalogservice-deployment 1/1 1 1 5h56m catalogservice elps/catalogservice:1.0.7 app=catalogservice
default deployment.apps/customerservice-deployment 1/1 1 1 5h56m customerservice elps/customerservice:1.0.7 app=customerservice
kube-system deployment.apps/calico-typha 0/0 0 0 5h58m calico-typha quay.io/calico/typha:v3.3.2 k8s-app=calico-typha
kube-system deployment.apps/coredns 2/2 2 2 6h11m coredns k8s.gcr.io/coredns:1.2.6 k8s-app=kube-dns
NAMESPACE NAME DESIRED CURRENT READY AGE CONTAINERS IMAGES SELECTOR
default replicaset.apps/articleservice-deployment-6d48989664 1 1 1 5h56m articleservice elps/articleservice:1.0.7 app=articleservice,pod-template-hash=6d48989664
default replicaset.apps/cartservice-deployment-6b844f45b8 1 1 1 5h56m cartservice elps/cartservice:1.0.7 app=cartservice,pod-template-hash=6b844f45b8
default replicaset.apps/catalogservice-deployment-d4bd6984c 1 1 1 5h56m catalogservice elps/catalogservice:1.0.7 app=catalogservice,pod-template-hash=d4bd6984c
default replicaset.apps/customerservice-deployment-7d6f77fdbb 1 1 1 5h56m customerservice elps/customerservice:1.0.7 app=customerservice,pod-template-hash=7d6f77fdbb
kube-system replicaset.apps/calico-typha-5fc4874c76 0 0 0 5h58m calico-typha quay.io/calico/typha:v3.3.2 k8s-app=calico-typha,pod-template-hash=5fc4874c76
kube-system replicaset.apps/coredns-86c58d9df4 2 2 2 6h10m coredns k8s.gcr.io/coredns:1.2.6 k8s-app=kube-dns,pod-template-hash=86c58d9df4
Ingress
is that you need. This is how it works:
internet
|
[ Ingress ]
--|-----|--
[ Services ]
Let's say you have any k8s Deployment with the label: app: deployment-01
with containerPort: 8888
So, you need to create:
If you want to reach service-01 by link http://myserver.com/service then your Service YAML should look like this:
apiVersion: v1
kind: Service
metadata:
name: service-01
spec:
selector:
app: deployment-01
ports:
- name: web
protocol: TCP
port: 8080
targetPort: 8888
and Ingress:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: ingress-01
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- host: myserver.com
http:
paths:
- path: /service
backend:
serviceName: service-01
servicePort: 8080
that's it!
Note: This assumes that you have already deployed the Ingress controller and it is working.