# creates a clusterk3dclustercreatemycluster-p"8081:80@loadbalancer"-p"8082:443@loadbalancer"--agents2# displays cluster information (kubectl configuration is automatically updated and set to use the new cluster context)kubectlcluster-info# ensures coredns and traefik (ingress controller) are deployed by default (k3s behavior)kubectlgetdeploy-nkube-system# (optional) writes and uses specific kubectl configurationexport KUBECONFIG="$(k3dkubeconfigwritemycluster)"
# creates a nginx (web server) deploymentkubectlcreatedeploymentnginx--image=nginx# exposes the deployment with a servicekubectlcreateserviceclusteripnginx--tcp=80:80# provides an ingress to the servicecat<<EOF|kubectlapply-f-apiVersion: networking.k8s.io/v1kind: Ingressmetadata: name: nginx annotations: ingress.kubernetes.io/ssl-redirect: "false"spec: rules: - host: nginx.dev.local http: paths: - path: / pathType: Prefix backend: service: name: nginx port: number: 80EOF# checks everything is okkubectlgetsvc,pod,deploy,ingress# makes sure the website can be reachedcurllocalhost:8081/