Ingress Controller
The first thing you need to talk to your cluster is an ingress controller. That’s what opens a connection from the world to the kubernetes network. kubectl has a proxy which is what is allowing me to connect like the dashboard to my web browser at the moment. But that’s just for control. To connect something real, like gitlab you need something else. And there’s a ton of them.
I’m reading kubernetes top ingress controllers to see if it’s any good. I’m not sure how much which ingress controller matters for me since I’m so small. I think whatever is easiest.
I hadn’t really considered this. However the article suggests you want two ingress controllers. One for LAN traffic and one for internet traffic. Good point. Right now, of course I just need internal traffic, but configuring it so it will be easy to add a second one later sounds like a good idea.
After reading the document I’m coming to the same conclusion as I did before reading the document. It’s either NGINX or Traefik. NGINX has been the reverse proxy I’ve been using for quite awhile. Setting it up here will be painless according to the article. However Traefik seems to be the new boy in town that all the cool kids are playing with. Well, I made a post on facebook asking opinions, not a bunch of people stepping up. I think I’m going to try traefik and see if I like it.
I’m going to try to do this supposedly working demo https://docs.traefik.io/user-guides/crd-acme/ it’s running out of a docker-compose. I’m going to try to wing it. Also, I’m not going to muck with https as of yet since I don’t feel like figuring out how to make this present on the internet just yet. So, I’m going to blow off the let’s encrypt stuff and all that. So, here we go.
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
name: ingressroutes.traefik.containo.us
spec:
group: traefik.containo.us
version: v1alpha1
names:
kind: IngressRoute
plural: ingressroutes
singular: ingressroute
scope: Namespaced
---
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
name: ingressroutetcps.traefik.containo.us
spec:
group: traefik.containo.us
version: v1alpha1
names:
kind: IngressRouteTCP
plural: ingressroutetcps
singular: ingressroutetcp
scope: Namespaced
---
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
name: middlewares.traefik.containo.us
spec:
group: traefik.containo.us
version: v1alpha1
names:
kind: Middleware
plural: middlewares
singular: middleware
scope: Namespaced
---
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
name: tlsoptions.traefik.containo.us
spec:
group: traefik.containo.us
version: v1alpha1
names:
kind: TLSOption
plural: tlsoptions
singular: tlsoption
scope: Namespaced
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
name: traefik-ingress-controller
rules:
- apiGroups:
- ""
resources:
- services
- endpoints
- secrets
verbs:
- get
- list
- watch
- apiGroups:
- extensions
resources:
- ingresses
verbs:
- get
- list
- watch
- apiGroups:
- extensions
resources:
- ingresses/status
verbs:
- update
- apiGroups:
- traefik.containo.us
resources:
- middlewares
verbs:
- get
- list
- watch
- apiGroups:
- traefik.containo.us
resources:
- ingressroutes
verbs:
- get
- list
- watch
- apiGroups:
- traefik.containo.us
resources:
- ingressroutetcps
verbs:
- get
- list
- watch
- apiGroups:
- traefik.containo.us
resources:
- tlsoptions
verbs:
- get
- list
- watch
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
name: traefik-ingress-controller
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: traefik-ingress-controller
subjects:
- kind: ServiceAccount
name: traefik-ingress-controller
namespace: default
denebeim@frankiemouse:~/kubernetes/traefik$ kubectl apply -f ingressroute.yaml
customresourcedefinition.apiextensions.k8s.io/ingressroutes.traefik.containo.us created
customresourcedefinition.apiextensions.k8s.io/ingressroutetcps.traefik.containo.us created
customresourcedefinition.apiextensions.k8s.io/middlewares.traefik.containo.us created
customresourcedefinition.apiextensions.k8s.io/tlsoptions.traefik.containo.us created
clusterrole.rbac.authorization.k8s.io/traefik-ingress-controller created
clusterrolebinding.rbac.authorization.k8s.io/traefik-ingress-controller created
Whoami service demo
apiVersion: v1
kind: Service
metadata:
name: traefik
spec:
ports:
- protocol: TCP
name: web
port: 8000
- protocol: TCP
name: admin
port: 8080
- protocol: TCP
name: websecure
port: 4443
selector:
app: traefik
---
apiVersion: v1
kind: Service
metadata:
name: whoami
spec:
ports:
- protocol: TCP
name: web
port: 80
selector:
app: whoami
denebeim@frankiemouse:~/kubernetes/traefik$ kubectl apply -f whoami.yaml
service/traefik created
service/whoami created
apiVersion: v1
kind: ServiceAccount
metadata:
namespace: default
name: traefik-ingress-controller
---
kind: Deployment
apiVersion: apps/v1
metadata:
namespace: default
name: traefik
labels:
app: traefik
spec:
replicas: 1
selector:
matchLabels:
app: traefik
template:
metadata:
labels:
app: traefik
spec:
serviceAccountName: traefik-ingress-controller
containers:
- name: traefik
image: traefik:v2.0
args:
- --api.insecure
- --accesslog
- --entrypoints.web.Address=:8000
- --entrypoints.websecure.Address=:4443
- --providers.kubernetescrd
- --certificatesresolvers.default.acme.tlschallenge
- --certificatesresolvers.default.acme.email=foo@you.com
- --certificatesresolvers.default.acme.storage=acme.json
# Please note that this is the staging Let's Encrypt server.
# Once you get things working, you should remove that whole line altogether.
- --certificatesresolvers.default.acme.caserver=https://acme-staging-v02.api.letsencrypt.org/directory
ports:
- name: web
containerPort: 8000
- name: websecure
containerPort: 4443
- name: admin
containerPort: 8080
---
kind: Deployment
apiVersion: apps/v1
metadata:
namespace: default
name: whoami
labels:
app: whoami
spec:
replicas: 2
selector:
matchLabels:
app: whoami
template:
metadata:
labels:
app: whoami
spec:
containers:
- name: whoami
image: containous/whoami
ports:
- name: web
containerPort: 80
denebeim@frankiemouse:~/kubernetes/traefik$ kubectl apply -f deploy.yaml
serviceaccount/traefik-ingress-controller created
deployment.apps/traefik created
deployment.apps/whoami created
Well, these all came up, but we know that it’s not reachable from the internet (it better not be!) and so the let’s encrypt cert must not be available. But it looks like the container came up anyway. We’ll see if it’s working. If not we’ll try removing the TLS stuff.
Need to install a proxy I guess sudo kubectl port-forward --address 0.0.0.0 service/traefik 8000:8000 8080:8080 443:4443 -n default this doesn’t return. I’m not sure how this is supposed to be set up for real, it’s kinda important.
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
name: simpleingressroute
namespace: default
spec:
entryPoints:
- web
routes:
- match: Host(`localhost`) && PathPrefix(`/notls`)
kind: Rule
services:
- name: whoami
port: 80
---
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
name: ingressroutetls
namespace: default
spec:
entryPoints:
- websecure
routes:
- match: Host(`localhost`) && PathPrefix(`/tls`)
kind: Rule
services:
- name: whoami
port: 80
tls:
certResolver: default
denebeim@frankiemouse:~/kubernetes/traefik$ curl http://localhost:8000/notls
Hostname: whoami-bd6b677dc-xptqx
IP: 127.0.0.1
IP: 10.244.1.5
RemoteAddr: 10.244.1.4:54508
GET /notls HTTP/1.1
Host: localhost:8000
User-Agent: curl/7.58.0
Accept: */*
Accept-Encoding: gzip
X-Forwarded-For: 127.0.0.1
X-Forwarded-Host: localhost:8000
X-Forwarded-Port: 8000
X-Forwarded-Proto: http
X-Forwarded-Server: traefik-74dfb956c5-w45x9
X-Real-Ip: 127.0.0.1
Well, lookie there. That seems to have worked like a champ. So, I think it works ok with no tls even when tls is configured but still broken.
Traefik is pretty cool, but I still don’t know how to get from it to the actual system. The kubectl proxy thing was ok for playing, but I think you need something real to do it.
Something real, and it doesn’t take traefik
This way works.
helm install --name metallb stable/metallb
apiVersion: v1
kind: ConfigMap
metadata:
namespace: default
name: metallb-config
data:
config: |
address-pools:
- name: default
protocol: layer2
addresses:
- 192.168.42.50-192.168.42.99
kubectl apply -f config.yaml
Metallb is a bare metal load balancer. Cheap, easy. Just define pools for it to divvy out from.
kubectl apply -f https://k8s.io/examples/service/load-balancer-example.yaml
denebeim@frankiemouse:~/kubernetes/metalLB$ kubectl apply -f https://k8s.io/examples/service/load-balancer-example.yaml
deployment.apps/hello-world created
kubectl expose deployment hello-world --type=LoadBalancer --name=my-service
kubectl get services my-service
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
my-service LoadBalancer 10.101.43.9 192.168.42.50 8080:30388/TCP 23s
denebeim@frankiemouse:~/kubernetes/metalLB$ curl 192.168.42.50:8080
Hello Kubernetes!
That’s creating 5 services that just echo hello. Then exposing the deployment, which talks to the metallb and gets an address.
And I’m too exhausted now.
Written with StackEdit.
No comments:
Post a Comment