Using Ubuntu’s MicroK8s Kubernetes environment to test a Nginx container with a NodePort and also Ingress so we can access from another machine.
install
$ sudo snap install microk8s --classicmicrok8s v1.18.2 from Canonical✓ installed
$ sudo usermod -a -G microk8s rrosso
$ microk8s.kubectl get all --all-namespacesNAMESPACE NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGEdefault service/kubernetes ClusterIP 10.152.183.1 <none> 443/TCP 2m29s
$ microk8s.kubectl get nodesNAME STATUS ROLES AGE VERSIONserver1 Ready <none> 3m v1.18.2-41+b5cdb79a4060a3
$ microk8s.enable dns dashboard...
$ watch microk8s.kubectl get all --all-namespaces</none></none>NOTE: alias the command
$ sudo snap alias microk8s.kubectl kubectlAdded: - microk8s.kubectl as kubectlnginx first attempt
$ kubectl create deployment nginx --image=nginxdeployment.apps/nginx created
$ kubectl get deploymentsNAME READY UP-TO-DATE AVAILABLE AGEnginx 1/1 1 1 9s
$ kubectl get podsNAME READY STATUS RESTARTS AGE
nginx-f89759699-jnlng 1/1 Running 0 15s
$ kubectl get all --all-namespaces
NAMESPACE NAME READY STATUS RESTARTS AGEdefault pod/nginx-f89759699-jnlng 1/1 Running 0 31s...NAMESPACE NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGEdefault service/kubernetes ClusterIP 10.152.183.1 <none> 443/TCP 94m...NAMESPACE NAME READY UP-TO-DATE AVAILABLE AGEdefault deployment.apps/nginx 1/1 1 1 31skube-system deployment.apps/coredns 1/1 1 1 90m...
NAMESPACE NAME DESIRED CURRENT READY AGEdefault replicaset.apps/nginx-f89759699 1 1 1 31skube-system replicaset.apps/coredns-588fd544bf 1 1 1 90m...
$ kubectl get all --all-namespacesNAMESPACE NAME READY STATUS RESTARTS AGEdefault pod/nginx-f89759699-jnlng 1/1 Running 0 2m38s...NAMESPACE NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE...NAMESPACE NAME READY UP-TO-DATE AVAILABLE AGEdefault deployment.apps/nginx 1/1 1 1 2m38s
NAMESPACE NAME DESIRED CURRENT READY AGEdefault replicaset.apps/nginx-f89759699 1 1 1 2m38s...
$ wget 10.152.183.151--2020-05-25 14:26:14-- http://10.152.183.151/Connecting to 10.152.183.151:80... connected.HTTP request sent, awaiting response... 404 Not Found2020-05-25 14:26:14 ERROR 404: Not Found.
$ kubectl get deploymentsNAME READY UP-TO-DATE AVAILABLE AGEnginx 1/1 1 1 3m40s
$ kubectl get podsNAME READY STATUS RESTARTS AGEnginx-f89759699-jnlng 1/1 Running 0 3m46s
$ microk8s.kubectl expose deployment nginx --port 80 --target-port 80 --type ClusterIP --selector=run=nginx --name nginxservice/nginx exposed
$ microk8s.kubectl get allNAME READY STATUS RESTARTS AGEpod/nginx-f89759699-jnlng 1/1 Running 0 9m29s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGEservice/kubernetes ClusterIP 10.152.183.1 <none> 443/TCP 103mservice/nginx ClusterIP 10.152.183.55 <none> 80/TCP 3m55s
NAME READY UP-TO-DATE AVAILABLE AGEdeployment.apps/nginx 1/1 1 1 9m29s
NAME DESIRED CURRENT READY AGEreplicaset.apps/nginx-f89759699 1 1 1 9m29s
$ wget 10.152.183.55--2020-05-25 14:33:02-- http://10.152.183.55/Connecting to 10.152.183.55:80... failed: Connection refused.</none></none></none>NOTE: Kubernetes does not provide a loadbalancer. It is assumed that loadbalancers are an external component. MicroK8s is not shipping any loadbalancer but even if it did there would not have been any nodes to balance load over. There is only one node so if you want to expose a service you should use the NodePort service type.
There is no external LB shipping with MicroK8s, therefore there is no way to appoint an (LB provided) external IP to a service. What you can do is to expose a service to a host’s port using NodePort.
nginx attempt 2
$ kubectl delete services nginx-serviceservice "nginx-service" deleted
$ kubectl delete deployment nginxdeployment.apps "nginx" deleted
$ kubectl create deployment nginx --image=nginxdeployment.apps/nginx created
$ kubectl expose deployment nginx --type NodePort --port=80 --name nginx-serviceservice/nginx-service exposed
$ kubectl get allNAME READY STATUS RESTARTS AGEpod/nginx-f89759699-jr4gz 1/1 Running 0 23s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGEservice/kubernetes ClusterIP 10.152.183.1 <none> 443/TCP 19hservice/nginx-service NodePort 10.152.183.229 <none> 80:30856/TCP 10s
NAME READY UP-TO-DATE AVAILABLE AGEdeployment.apps/nginx 1/1 1 1 23s
NAME DESIRED CURRENT READY AGEreplicaset.apps/nginx-f89759699 1 1 1 23s
$ wget 10.152.183.229Connecting to 10.152.183.229:80... connected.HTTP request sent, awaiting response... 200 OK2020-05-26 08:05:22 (150 MB/s) - "index.html" saved [612/612]</none></none>ingress
$ cat ingress-nginx.yamlapiVersion: networking.k8s.io/v1beta1kind: Ingressmetadata: name: http-ingressspec: rules: - http: paths: - path: / backend: serviceName: nginx-service servicePort: 80
$ kubectl apply -f ingress-nginx.yamlingress.networking.k8s.io/http-ingress createdNOTE: https://192.168.1.112/ pulls up Nginx homepage
after reboot:
- grafana console works
https://192.168.1.112:16443/api/v1/namespaces/kube-system/services/monitoring-grafana/proxy/?orgId=1 - ingress for nginx container works
https://192.168.1.112/ - kubernetes dashboard does not work. need to run a proxy ```bash
microk8s.kubectl proxy —accept-hosts=.* —address=0.0.0.0 &
<http://192.168.1.112:8001/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy>
next
- persistent storage test