K8s/Ingress: Difference between revisions

From Chorke Wiki
Jump to navigation Jump to search
 
(5 intermediate revisions by the same user not shown)
Line 1: Line 1:
==External==
==External==
<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
kubectl get ns|grep external
kubectl get   ns|grep   external
kubectl delete namespace external
kubectl delete namespace external
kubectl create namespace external
kubectl create namespace external
Line 270: Line 270:
|valign='top'|
|valign='top'|


===Academia » Portal===
===Agronomy » Portal===
<syntaxhighlight lang="yaml" highlight="14,18" line>
<syntaxhighlight lang="yaml" highlight="14,18" line>
cat << YML | kubectl apply -n academia -f -
cat << YML | kubectl apply -n agronomy -f -
---
---
apiVersion: networking.k8s.io/v1
apiVersion: networking.k8s.io/v1
kind: Ingress
kind: Ingress
metadata:
metadata:
   name: academia
   name: agronomy
   namespace: academia
   namespace: agronomy
   labels:
   labels:
     app.kubernetes.io/version: 1.0.0
     app.kubernetes.io/version: 1.0.0
     app.kubernetes.io/name: academia
     app.kubernetes.io/name: agronomy
     app.kubernetes.io/instance: academia
     app.kubernetes.io/instance: agronomy
     app.kubernetes.io/managed-by: kubectl
     app.kubernetes.io/managed-by: kubectl
   annotations:
   annotations:
Line 289: Line 289:
   ingressClassName: nginx
   ingressClassName: nginx
   rules:
   rules:
     - host: "academia.chorke.local"
     - host: "agronomy.chorke.local"
       http:
       http:
         paths:
         paths:
Line 296: Line 296:
             backend:
             backend:
               service:
               service:
                 name: academia
                 name: agronomy
                 port:
                 port:
                   number: 3000
                   number: 3000
Line 303: Line 303:
             backend:
             backend:
               service:
               service:
                 name: academia
                 name: agronomy
                 port:
                 port:
                   number: 9004
                   number: 9004
Line 310: Line 310:
             backend:
             backend:
               service:
               service:
                 name: academia
                 name: agronomy
                 port:
                 port:
                   number: 9003
                   number: 9003
Line 317: Line 317:
             backend:
             backend:
               service:
               service:
                 name: academia
                 name: agronomy
                 port:
                 port:
                   number: 9002
                   number: 9002
Line 324: Line 324:
             backend:
             backend:
               service:
               service:
                 name: academia
                 name: agronomy
                 port:
                 port:
                   number: 9000
                   number: 9000
Line 559: Line 559:
|valign='top'|
|valign='top'|
* [https://medium.com/@luis.laredo.vel/configuring-pgadmin-to-access-the-backstage-databases-in-a-kubernetes-cluster-953ee087e41d K8s » Configuring PgAdmin4]
* [https://medium.com/@luis.laredo.vel/configuring-pgadmin-to-access-the-backstage-databases-in-a-kubernetes-cluster-953ee087e41d K8s » Configuring PgAdmin4]
* [https://stackoverflow.com/questions/51744536/ K8s » Ingress » CORS Rules]
* [[K8s/CSI Hostpath Driver|K8s » CSI Hostpath Driver]]
* [[K8s/CSI Hostpath Driver|K8s » CSI Hostpath Driver]]
* [[K8s/HAProxy/Ingress|K8s » HAProxy » Ingress]]
* [[K8s/Nginx/Ingress|K8s » Nginx » Ingress]]


|-
|-

Latest revision as of 12:00, 30 March 2025

External

kubectl get    ns|grep   external
kubectl delete namespace external
kubectl create namespace external

Internal

kubectl get    ns|grep   internal
kubectl delete namespace internal
kubectl create namespace internal
kubectl get    ns|grep   academia
kubectl delete namespace academia
kubectl create namespace academia
kubectl get    ns|grep   agronomy
kubectl delete namespace agronomy
kubectl create namespace agronomy

cat << YML|kubectl apply -n internal -f -
---
apiVersion: v1
kind: Service
metadata:
  name: minikube-host
  namespace: internal
  labels:
    app.kubernetes.io/version: 1.0.0
    app.kubernetes.io/managed-by: kubectl
    app.kubernetes.io/name: minikube-host
    app.kubernetes.io/instance: minikube-host
spec:
  type: ExternalName
  externalName: host.minikube.internal
YML
cat << YML|kubectl apply -n academia -f -
---
apiVersion: v1
kind: Service
metadata:
  name: academia
  namespace: academia
  labels:
    app.kubernetes.io/version: 1.0.0
    app.kubernetes.io/name: academia
    app.kubernetes.io/instance: academia
    app.kubernetes.io/managed-by: kubectl
spec:
  type: ExternalName
  externalName: host.minikube.internal
YML
cat << YML|kubectl apply -n agronomy -f -
---
apiVersion: v1
kind: Service
metadata:
  name: agronomy
  namespace: agronomy
  labels:
    app.kubernetes.io/version: 1.0.0
    app.kubernetes.io/name: agronomy
    app.kubernetes.io/instance: agronomy
    app.kubernetes.io/managed-by: kubectl
spec:
  type: ExternalName
  externalName: host.minikube.internal
YML

Internal » HAProxy

cat << YML | kubectl apply -n internal -f -
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: haproxy
  namespace: internal
  labels:
    app.kubernetes.io/version: 1.0.0
    app.kubernetes.io/managed-by: kubectl
    app.kubernetes.io/name: minikube-host
    app.kubernetes.io/instance: minikube-host
spec:
  ingressClassName: nginx
  rules:
    - host: "host.k8s.local"
      http:
        paths:
          - path: /
            pathType: ImplementationSpecific
            backend:
              service:
                name: minikube-host
                port:
                  number: 80
YML

Internal » Apache

cat << YML | kubectl apply -n internal -f -
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: apache
  namespace: internal
  labels:
    app.kubernetes.io/version: 1.0.0
    app.kubernetes.io/managed-by: kubectl
    app.kubernetes.io/name: minikube-host
    app.kubernetes.io/instance: minikube-host
spec:
  ingressClassName: nginx
  rules:
    - host: "apache.host.k8s.local"
      http:
        paths:
          - path: /
            pathType: ImplementationSpecific
            backend:
              service:
                name: minikube-host
                port:
                  number: 2013
YML

Internal » Nginx

cat << YML | kubectl apply -n internal -f -
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: nginx
  namespace: internal
  labels:
    app.kubernetes.io/version: 1.0.0
    app.kubernetes.io/managed-by: kubectl
    app.kubernetes.io/name: minikube-host
    app.kubernetes.io/instance: minikube-host
spec:
  ingressClassName: nginx
  rules:
    - host: "nginx.host.k8s.local"
      http:
        paths:
          - path: /
            pathType: ImplementationSpecific
            backend:
              service:
                name: minikube-host
                port:
                  number: 2015
YML

Internal » GitLab

cat << YML | kubectl apply -n internal -f -
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: gitlab
  namespace: internal
  labels:
    app.kubernetes.io/version: 1.0.0
    app.kubernetes.io/managed-by: kubectl
    app.kubernetes.io/name: minikube-host
    app.kubernetes.io/instance: minikube-host
spec:
  ingressClassName: nginx
  rules:
    - host: "gitlab.host.k8s.local"
      http:
        paths:
          - path: /
            pathType: ImplementationSpecific
            backend:
              service:
                name: minikube-host
                port:
                  number: 1080
YML

Internal » MinIO

cat << YML | kubectl apply -n internal -f -
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: minio
  namespace: internal
  labels:
    app.kubernetes.io/version: 1.0.0
    app.kubernetes.io/managed-by: kubectl
    app.kubernetes.io/name: minikube-host
    app.kubernetes.io/instance: minikube-host
  annotations:
    nginx.ingress.kubernetes.io/proxy-body-size: '0'
spec:
  ingressClassName: nginx
  rules:
    - host: "minio.host.k8s.local"
      http:
        paths:
          - path: /
            pathType: ImplementationSpecific
            backend:
              service:
                name: minikube-host
                port:
                  number: 9801
    - host: "s3.host.k8s.local"
      http:
        paths:
          - path: /
            pathType: ImplementationSpecific
            backend:
              service:
                name: minikube-host
                port:
                  number: 9800
YML

Agronomy » Portal

cat << YML | kubectl apply -n agronomy -f -
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: agronomy
  namespace: agronomy
  labels:
    app.kubernetes.io/version: 1.0.0
    app.kubernetes.io/name: agronomy
    app.kubernetes.io/instance: agronomy
    app.kubernetes.io/managed-by: kubectl
  annotations:
    nginx.ingress.kubernetes.io/proxy-body-size: '0'
spec:
  ingressClassName: nginx
  rules:
    - host: "agronomy.chorke.local"
      http:
        paths:
          - path: /
            pathType: ImplementationSpecific
            backend:
              service:
                name: agronomy
                port:
                  number: 3000
          - path: /services/flair/
            pathType: ImplementationSpecific
            backend:
              service:
                name: agronomy
                port:
                  number: 9004
          - path: /services/quote/
            pathType: ImplementationSpecific
            backend:
              service:
                name: agronomy
                port:
                  number: 9003
          - path: /services/audit/
            pathType: ImplementationSpecific
            backend:
              service:
                name: agronomy
                port:
                  number: 9002
          - path: /services/users/
            pathType: ImplementationSpecific
            backend:
              service:
                name: agronomy
                port:
                  number: 9000
YML

Ingress » Nginx

ConfigMap » tcp-services

cat << YML | kubectl apply -n ingress-nginx -f -
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: tcp-services
  namespace: ingress-nginx
  labels:
    app.kubernetes.io/component: controller
    app.kubernetes.io/instance: ingress-nginx
    app.kubernetes.io/name: ingress-nginx
data:
  5432: "postgresql/postgresql:5432"
  6379: "redis/redis-headless:6379"
YML

ConfigMap » udp-services

cat << YML | kubectl apply -n ingress-nginx -f -
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: udp-services
  namespace: ingress-nginx
  labels:
    app.kubernetes.io/component: controller
    app.kubernetes.io/instance: ingress-nginx
    app.kubernetes.io/name: ingress-nginx
data:
  1194: "internal/minikube-host:1194"
  53: "kube-system/kube-dns:53"
YML

Service » ingress-nginx

cat << YML | kubectl apply -n ingress-nginx -f -
---
apiVersion: v1
kind: Service
metadata:
  name: ingress-nginx
  namespace: ingress-nginx
  labels:
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/part-of: ingress-nginx
spec:
  type: LoadBalancer
  ports:
    - name: http
      port: 80
      targetPort: 80
      protocol: TCP
    - name: https
      port: 443
      targetPort: 443
      protocol: TCP
    - name: proxied-tcp-5432
      port: 5432
      targetPort: 5432
      protocol: TCP
    - name: proxied-tcp-6379
      port: 6379
      targetPort: 6379
      protocol: TCP
    - name: proxied-udp-1194
      port: 1194
      targetPort: 1194
      protocol: UDP
    - name: proxied-udp-53
      port: 53
      targetPort: 53
      protocol: UDP
  selector:
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/part-of: ingress-nginx
YML

kubectl -n ingress-nginx rollout restart deploy/ingress-nginx-controller
kubectl -n ingress-nginx rollout history deploy/ingress-nginx-controller
kubectl -n ingress-nginx rollout status  deploy/ingress-nginx-controller

Minikube » Tunnel

# check minikube user either exists or not
cat /etc/passwd|grep minikube
sudo usermod -aG sudo minikube
# minikube no-password sudo access add to EOL
sudo visudo
minikube ALL=(ALL) NOPASSWD: ALL
# login to minikube user and start tunneling
sudo -i -u minikube
minikube tunnel

Playground

kubectl -n ingress-nginx exec -it svc/ingress-nginx-controller -- cat template/nginx.tmpl
kubectl -n ingress-nginx exec -it svc/ingress-nginx-controller -- cat /etc/resolv.conf
kubectl -n ingress-nginx exec -it svc/ingress-nginx-controller -- cat nginx.conf
kubectl -n ingress-nginx exec -it svc/ingress-nginx-controller -- cat /etc/hosts

kubectl -n external get endpoints
kubectl -n external get service
kubectl -n external get ingress
kubectl -n internal get endpoints
kubectl -n internal get service
kubectl -n internal get ingress
kubectl config get-contexts
sudo -i -u minikube
helm list -A

kubectl get all -A
kubectl get ns
kubectl -n ingress-nginx exec -it svc/ingress-nginx-controller -c controller -- bash
kubectl -n ingress-nginx exec -it svc/ingress-nginx-controller -- bash

sudo vim /etc/apache2/sites-enabled/000-default.conf
sudo vim /etc/apache2/ports.conf
sudo apachectl -t
sudo systemctl restart apache2.service
sudo systemctl reload apache2.service
systemctl status apache2.service

References