Minikube Registry

From Chorke Wiki
Revision as of 10:10, 3 July 2024 by Shahed (talk | contribs) (→‎Ingress)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
minikube stop
minikube delete --all
rm -rf ${HOME}/.minikube/*
minikube start
minikube docker-env
minikube addons list
for p in ingress ingress-dns registry dashboard metrics-server;\
do minikube addons enable ${p};done
minikube addons list

kubectl get ns
kubectl get all
kubectl get all  -A
kubectl get pods -A
kubectl get namespaces
minikube kubectl -- get ns
minikube kubectl -- get all
minikube kubectl -- get all  -A
minikube kubectl -- get pods -A
minikube kubectl -- get namespaces
kubectl get  all -n kube-system
kubectl get  configmap -n kube-system
kubectl get  configmap coredns -n kube-system
kubectl edit configmap coredns -n kube-system
kubectl get  configmap coredns -n kube-system -o yaml

Ingress

# minikube nameserver ip
printf -v MINIKUBE_NSLOOKUP '%s' $(minikube ip)

# minikube find coredns last entry
CONFIGMAP_COREDNS_FIND=$(cat <<QRY
        }\n\
        cache 30\n\
        loop\n\
        reload\n\
        loadbalance\n\
    }
QRY
)
# minikube fill coredns last entry
CONFIGMAP_COREDNS_FILL=$(cat <<UPD
${CONFIGMAP_COREDNS_FIND}\n\
    k8s.local:53 {\n\
        errors\n\
        cache 30\n\
        forward . ${MINIKUBE_NSLOOKUP}\n\
    }
UPD
)

K8s » CoreDNS


# minikube update coredns entry for k8s.local
kubectl get configmap coredns -n kube-system -o yaml \
 | sed -z "s|${CONFIGMAP_COREDNS_FIND}|$(echo "${CONFIGMAP_COREDNS_FILL}")|" \
 | kubectl apply -n kube-system -f -

K8s » Registry


cat << YML | kubectl -n kube-system apply -f -
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: registry
  namespace: kube-system
  labels:
    app.kubernetes.io/version: 1.0.0
    app.kubernetes.io/name: registry
    app.kubernetes.io/instance: registry
    app.kubernetes.io/managed-by: Chorke-Academia-Inc
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/proxy-body-size: "0"
spec:
  ingressClassName: nginx
  rules:
    - host: "registry.k8s.local"
      http:
        paths:
          - path: /
            pathType: ImplementationSpecific
            backend:
              service:
                name: registry
                port:
                  number: 80
YML
cat << YML | kubectl -n kube-system delete -f -
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: registry
  namespace: kube-system
  labels:
    app.kubernetes.io/version: 1.0.0
    app.kubernetes.io/name: registry
    app.kubernetes.io/instance: registry
    app.kubernetes.io/managed-by: Chorke-Academia-Inc
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/proxy-body-size: "0"
spec:
  ingressClassName: nginx
  rules:
    - host: "registry.k8s.local"
      http:
        paths:
          - path: /
            pathType: ImplementationSpecific
            backend:
              service:
                name: registry
                port:
                  number: 80
YML

kubectl run -i --tty --rm debug --image=alpine  --restart=Never -- nslookup registry.k8s.local
kubectl run -i --tty --rm debug --image=alpine  --restart=Never -- ping registry.k8s.local
kubectl -n kube-system get ingress registry -o yaml
nslookup registry.k8s.local $(minikube ip)

K8s » DNS Config


RESOLVE='/etc/resolv.conf';\
printf -v K8S_DNS '%s' $(minikube ip);\
if  [ -f ${RESOLVE} ]&&[ "$(grep -c ${K8S_DNS} ${RESOLVE})" == 0 ];then\
 cat << EOF | sudo tee -a ${RESOLVE} >/dev/null

# minikube dns server
nameserver ${K8S_DNS}
EOF
fi;\
cat ${RESOLVE}

nslookup registry.k8s.local
ping registry.k8s.local

xdg-open http://registry.k8s.local/v2/_catalog &>/dev/null &
gnome-open http://registry.k8s.local/v2/_catalog &>/dev/null &
x-www-browser http://registry.k8s.local/v2/_catalog &>/dev/null &
sensible-browser http://registry.k8s.local/v2/_catalog &>/dev/null &

K8s » Docker


cat << EXE | sudo bash
cat /etc/docker/daemon.json \
 |jq '."insecure-registries"=["registry.k8s.local"]' \
 |tee /etc/docker/daemon.json >/dev/null
systemctl restart docker
EXE
cat << EXE | bash
cat /etc/docker/daemon.json|jq .
systemctl status docker
minikube  status
minikube  start
EXE

cat << EXE | bash
docker pull alpine:latest 
docker tag  alpine:latest registry.k8s.local/alpine:latest
docker push    registry.k8s.local/alpine:latest
curl -s http://registry.k8s.local/v2/_catalog|jq -r '.repositories[0]'
curl -s http://registry.k8s.local/v2/_catalog|jq -r '.repositories|length'
EXE

Playground

watch kubectl get pods -n kube-system
watch minikube ssh -- cat /etc/hosts

References