Minikube Ingress DNS
minikube stop
minikube delete --all
rm -rf ${HOME}/.minikube/*
|
minikube start
minikube docker-env
minikube addons list
|
minikube addons enable ingress
minikube addons enable ingress-dns
minikube addons enable metrics-server
|
| ||
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 DNS
kubectl edit configmap coredns -n kube-system apiVersion: v1
data:
Corefile: |
.:53 {
log
errors
reload
loadbalance
}
k8s.local:53 {
errors
cache 30
forward . 192.168.49.2
}
academia.local:53 {
errors
cache 30
forward . 192.168.49.2
}
kind: ConfigMap
metadata:
creationTimestamp: "2023-07-04T00:08:54Z"
name: coredns
namespace: kube-system
resourceVersion: "300"
uid: d8eec45d-1452-467f-8861-8811658c773a
| |
K8s » Dashboard | |
cat <<EOF | kubectl apply -n kubernetes-dashboard -f -
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: kubernetes-dashboard
labels:
helm.sh/chart: kubernetes-dashboard-1.0.0
app.kubernetes.io/name: kubernetes-dashboard
app.kubernetes.io/instance: kubernetes-dashboard
app.kubernetes.io/version: "1.0.0"
app.kubernetes.io/managed-by: Helm
spec:
ingressClassName: nginx
rules:
- host: "www.k8s.local"
http:
paths:
- path: /
pathType: ImplementationSpecific
backend:
service:
name: kubernetes-dashboard
port:
number: 80
EOF
|
cat <<EOF | kubectl delete -n kubernetes-dashboard -f -
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: kubernetes-dashboard
labels:
helm.sh/chart: kubernetes-dashboard-1.0.0
app.kubernetes.io/name: kubernetes-dashboard
app.kubernetes.io/instance: kubernetes-dashboard
app.kubernetes.io/version: "1.0.0"
app.kubernetes.io/managed-by: Helm
spec:
ingressClassName: nginx
rules:
- host: "www.k8s.local"
http:
paths:
- path: /
pathType: ImplementationSpecific
backend:
service:
name: kubernetes-dashboard
port:
number: 80
EOF
|
| |
kubectl run -i --tty --rm debug --image=alpine --restart=Never -- nslookup www.k8s.local
kubectl run -i --tty --rm debug --image=alpine --restart=Never -- ping www.k8s.local
nslookup www.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
nameserver ${K8S_DNS}
EOF
fi;\
cat ${RESOLVE}
| |
| |
nslookup www.k8s.local
|
ping www.k8s.local
|
| |
xdg-open http://www.k8s.local &>/dev/null &
gnome-open http://www.k8s.local &>/dev/null &
|
x-www-browser http://www.k8s.local &>/dev/null &
sensible-browser http://www.k8s.local &>/dev/null &
|
Dynamic DNS Script
cat << EVT | sudo tee /etc/network/if-up.d/minikube-ifupdown
#!/bin/bash
: '
@vendor Chorke Academia, Inc.
@web https://cdn.chorke.org/docs/academia
@version 1.0.00
@since 1.0.00
'
USER_TARGET="${USER}"
function silent_exit(){
exit 0
}
function verify_addr(){
printf -v DNS_HOST '%s' \$(sudo -u \${USER_TARGET} minikube ip)
if [[ "\${DNS_HOST}" =~ ^(([1-9]?[0-9]|1[0-9][0-9]|2([0-4][0-9]|5[0-5]))\.){3}([1-9]?[0-9]|1[0-9][0-9]|2([0-4][0-9]|5[0-5]))$ ]]; then
if [[ "\${DNS_HOST}" == '127.0.0.1' ]]; then silent_exit; fi
else silent_exit; fi
}
function verify_kube(){
printf -v K8S_JSON '%s' \$(sudo -u \${USER_TARGET} minikube status -o 'json');
printf -v K8S_REST '%s' \$(echo \${K8S_JSON} | jq -r '.APIServer')
printf -v K8S_KUBE '%s' \$(echo \${K8S_JSON} | jq -r '.Kubelet')
printf -v K8S_HOST '%s' \$(echo \${K8S_JSON} | jq -r '.Host')
KUBE_STATUS='Running'
if [[ "\${K8S_HOST}" == "\${KUBE_STATUS}" ]]&&[[ "\${K8S_KUBE}" == "\${KUBE_STATUS}" ]]&&
[[ "\${K8S_REST}" == "\${KUBE_STATUS}" ]]; then verify_addr
else silent_exit; fi
}
function verify_mini(){
if [[ -x "\$(command -v minikube)" ]]&&[[ -x "\$(command -v jq)" ]]; then verify_kube; else silent_exit; fi
}
function verify_link(){
HOST_ETHERS="\$(ip -j link show | jq -r '.[].ifname'| paste -sd' ' -)"
if [[ "\${HOST_ETHERS}" =~ "\${IFACE}" ]]; then verify_mini; else silent_exit; fi
}
function verify(){
verify_link
}
function amend_nameserver(){
RESOLV_CONF='/etc/resolv.conf'
if [[ -f \${RESOLV_CONF} ]]&&[[ "\$(grep -c \${DNS_HOST} \${RESOLV_CONF})" == 0 ]];then
cat << CON | sudo tee -a \${RESOLV_CONF} >/dev/null
# minikube dns server
nameserver \${DNS_HOST}
CON
else silent_exit; fi
}
function handle(){
amend_nameserver
}
function init(){
verify
handle
}
init
EVT
sudo chmod +x /etc/network/if-up.d/minikube-ifupdown
Playground
minikube status -f '{{.Kubeconfig}}'
minikube status -f '{{.APIServer}}'
minikube status -f '{{.Kubelet}}'
minikube status -f '{{.Worker}}'
minikube status -f '{{.Host}}'
|
minikube status -o 'json' | jq -r '.Kubeconfig'
minikube status -o 'json' | jq -r '.APIServer'
minikube status -o 'json' | jq -r '.Kubelet'
minikube status -o 'json' | jq -r '.Worker'
minikube status -o 'json' | jq -r '.Host'
|
ip -j link show | jq -r '.[].ifname'| paste -sd' ' -
ip -j link show type bridge | jq -r '.[].ifname'
ip -o link show | awk -F': ' '{print $2}'
ip -j link show | jq -r '.[].ifname'
ls /sys/class/net
|
| ||
minikube status -f '{{- if .TimeToStop }} timeToStop: {{.TimeToStop}} {{- end }}'
minikube status -f '{{- if .DockerEnv }} docker-env: {{.DockerEnv}} {{- end }}'
minikube status -o 'json' | jq
|
ip -j link show | jq -r '.[]|select(.link_type=="loopback")'
ip -j link show | jq -r '.[]|select(.link_type=="ether")'
ip -j link show | jq -r '.[]|select(.link_type==null)'
| |
| ||
sudo ln -s /etc/network/if-up.d/minikube-ifupdown /etc/network/if-down.d/minikube-ifupdown
sudo rm -f /etc/network/if-down.d/minikube-ifupdown
|
References
| ||