kube-system namespace içinde nginx-ingress için bir default-http-backend servisi açmak.
Aşağıdaki komuta baktığımda varsayılan bir servis olmadığını farkettim.
- yol: helm charts ile kurulum yapılırken aşğıdaki gibi enable yapılabilir.
cat > k8s-old-ingress.yaml <<EOF
controller:
hostNetwork: true
dnsPolicy: ClusterFirstWithHostNet
kind: DaemonSet
podAnnotations:
prometheus.io/port: "10254"
prometheus.io/scrape: "true"
publishService:
enabled: false
service:
enabled: false
defaultBackend:
enabled: true
EOF
Not: Ingress controller, pod’lara trafigi iletmek için servisleri(kube-proxy) kullanmaz. Kendi özel LB algoritmalarını ve affinity ayalarını kullanmak için epointsler üzerinden çalışır. Dolayısı ile “dnsPolicy: ClusterFirstWithHostNet” ayarını kullanmasanızda olur.
Yukarıdaki işlem sonunda ingress instance için de bir annotaion eklmekte gerekmektedir;
2. yol: kendi özel dockerfile, pod ve servisi oluşturmak
bu servisin iki temel özelliği olmalı / ->404 ve /healthz -> 200 …
Dockerfile:
FROM nginx:latest
ENV DEBIAN_FRONTEND=noninteractive
RUN rm /usr/share/nginx/html/50x.html && \
rm /usr/share/nginx/html/index.html && \
rm /etc/nginx/conf.d/default.conf && \
ln -sf /dev/stdout /var/log/nginx/access.log && \
ln -sf /dev/stderr /var/log/nginx/error.log
COPY default.conf /etc/nginx/conf.d/default.conf
ENV TZ=Turkey
RUN ln -sf /usr/share/zoneinfo/$TZ /etc/localtime
RUN echo "$TZ" > /etc/timezone
RUN apt-get update && apt-get upgrade -y && apt-get install -y iputils-ping bind9-host tmux iproute2 curl
CMD ["nginx", "-g", "daemon off;"]default.conf:
server {
listen 80;
server_name localhost;
charset utf-8;
access_log off;
location / {
return 404;
}
location /healthz {
return 200 "healthy\n";
}
location /metrics {
stub_status on;
}
#error_page 404 =200 /;
#error_page 500 =200 /;
}
yukarıdak 2 dosyayı bir dizine kaydedin. Sonarada aşağdaki gibi build edin.
docker build -t default-http-backend:v1.0 -t default-http-backend:latest .
tabi en sonunda “kubectl -n kube-system” ile çalıştırabileceginiz. yaml dosyası
apiVersion: apps/v1
kind: Deployment
namespace: kube-system
metadata:
name: default-http-backend
labels:
app: default-http-backend
spec:
replicas: 1
selector:
matchLabels:
app: default-http-backend
template:
metadata:
labels:
app: default-http-backend
spec:
containers:
- name: default-http-backend
image: registry.mhrs.gov.tr/default-http-backend:latest
ports:
- containerPort: 80
resources:
limits:
cpu: 512m
memory: 512Mi
requests:
cpu: 100m
memory: 100Mi
imagePullSecrets:
- name: regcred
---
apiVersion: v1
kind: Service
namespace: kube-system
metadata:
name: default-http-backend
spec:
selector:
app: default-http-backend
ports:
- name: http
protocol: TCP
port: 80
targetPort: 80
ve sonuc:
peki bu default http backend ne işe yarar işte onu cözemedim? :-)
tabi bu default-http-backend yerine özel bir serviste ingress yaml dosyanızda belirtelbilirsiniz.
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
nginx.ingress.kubernetes.io/proxy-connect-timeout: '10'
nginx.ingress.kubernetes.io/proxy-read-timeout: '90'
nginx.ingress.kubernetes.io/proxy-send-timeout: '80'
nginx.ingress.kubernetes.io/proxy-body-size: 5m
nginx.ingress.kubernetes.io/configuration-snippet: |
more_set_headers "X-Robots-Tag: noindex";
more_set_headers X-Robots-Tag: googlebot: nofollow;
more_set_headers X-Robots-Tag: otherbot: noindex, nofollow;
error_page 503 https://cdn.ornek.com/images/bakim/index.html;
name: msrs-ingress
spec:
defaultBackend:
service:
name: testing
port:
number: 80
rules:
- http:
....
Son olarak bu işlem ingress yaml dosyasında da tanımlanabilir;
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
name: alp-ingress
namespace: default
spec:
ingressClassName: nginx
defaultBackend:
service:
name: alp-servis
port:
number: 80
rules:
- http:
paths:
- path: /alp
pathType: Prefix
backend:
service:
name: alp-servis
port:
number: 80