Skip to content

Instantly share code, notes, and snippets.

apiVersion: v1
kind: Ingress
metadata:
name: number-crunch-ingress
spec:
ingressClassName: number-crunch-ingress-name
rules:
- http:
paths:
- path: /square-root

Ansible playbook

- hosts: testvms
  remote_user: ubuntu
  become: yes
  ignore_errors: true

  tasks:
  - name: install nginx
    ansible.builtin.apt:
ubuntu@microk8s70:~$ sudo iptables -t nat -L PREROUTING
Chain PREROUTING (policy ACCEPT)
target     prot opt source               destination         
cali-PREROUTING  all  --  anywhere             anywhere             /* cali:6gwbT8clXdHdC1b1 */
KUBE-SERVICES  all  --  anywhere             anywhere             /* kubernetes service portals */
ubuntu@microk8s70:~$ sudo iptables -t nat -L KUBE-SERVICES
Chain KUBE-SERVICES (2 references)
target     prot opt source               destination         
KUBE-SVC-WV6VKHDJQKB2TQC4  tcp  --  anywhere             10.152.183.159       /* container-registry/registry:registry cluster IP */ tcp dpt:5000
ubuntu@microk8s70:~$ sudo iptables -t nat -L KUBE-NODEPORTS
Chain KUBE-NODEPORTS (1 references)
target     prot opt source               destination         
KUBE-EXT-PU6N6JOCTJFVBXKG  tcp  --  anywhere             anywhere             /* default/number-crunch-service:name-of-service-port */ tcp dpt:32155
KUBE-EXT-WV6VKHDJQKB2TQC4  tcp  --  anywhere             anywhere             /* container-registry/registry:registry */ tcp dpt:32000

ubuntu@microk8s70:~$ sudo iptables -t nat -L KUBE-SVC-PU6N6JOCTJFVBXKG
Chain KUBE-SVC-PU6N6JOCTJFVBXKG (2 references)
target     prot opt source               destination         
ubuntu@client:~/projects/new-kube-config$ curl http://10.129.204.65:32155/square-root/4
{"InputNumber":4,"SquareRoot":2}
ubuntu@client:~/projects/new-kube-config$ curl http://10.129.204.132:32155/square-root/4
{"InputNumber":4,"SquareRoot":2}
ubuntu@client:~/projects/new-kube-config$ curl http://10.129.204.188:32155/square-root/4
{"InputNumber":4,"SquareRoot":2}
ubuntu@controller:~/kube-config$ kubectl get services
NAME                    TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)          AGE
kubernetes              ClusterIP   10.152.183.1    <none>        443/TCP          2d15h
number-crunch-service   NodePort    10.152.183.70   <none>        8080:32155/TCP   10s

ubuntu@controller:~/kube-config$ kubectl get pods -o wide
NAME                                 READY   STATUS    RESTARTS   AGE   IP            NODE         NOMINATED NODE   READINESS GATES
number-crunch-app-7b9d574b47-df4h5   1/1     Running   0          12s   10.1.209.9    microk8s60   <none>           <none>
number-crunch-app-7b9d574b47-xv48x   1/1     Running   0          12s   10.1.131.8    microk8s70   <none>           <none>
ubuntu@microk8s70:~$ sudo iptables -t nat -L PREROUTING
Chain PREROUTING (policy ACCEPT)
target     prot opt source               destination         
cali-PREROUTING  all  --  anywhere             anywhere             /* cali:6gwbT8clXdHdC1b1 */
KUBE-SERVICES  all  --  anywhere             anywhere             /* kubernetes service portals */
ubuntu@microk8s70:~$ sudo iptables -t nat -L KUBE-SERVICES
Chain KUBE-SERVICES (2 references)
target     prot opt source               destination         
KUBE-SVC-WV6VKHDJQKB2TQC4  tcp  --  anywhere             10.152.183.159       /* container-registry/registry:registry cluster IP */ tcp dpt:5000
ubuntu@controller:~$ kubectl get pods -o wide
NAME                                READY   STATUS    RESTARTS   AGE   IP            NODE         NOMINATED NODE   READINESS GATES
nginx-deployment-565887c86b-kcp5z   1/1     Running   0          34h   10.1.131.5    microk8s70   <none>           <none>
nginx-deployment-565887c86b-59d25   1/1     Running   0          34h   10.1.73.131   microk8s40   <none>           <none>
ubuntu@controller:~$ kubectl get services
NAME            TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)    AGE
kubernetes      ClusterIP   10.152.183.1    <none>        443/TCP    2d10h
nginx-service   ClusterIP   10.152.183.23   <none>        8080/TCP   26h

How to build a container image from a local Dockerfile

Open terminal and switch to the folder where the Dockerfile is located.

  docker build . -t number-crunch:1.0.0

Note: Use the -t option to give a name and tag to the image. If not the name and tag fields will be blank when you list your images with docker image ls.

require 'webrick'
require 'webrick/httpproxy'
proxy = WEBrick::HTTPProxyServer.new Port: 8000
trap 'INT' do proxy.shutdown end
trap 'TERM' do proxy.shutdown end
proxy.start