Introduction

Outline steps to implement some of the Kubernetes advanced concepts.

  1. Create a local Kubernetes in Docker (KinD) cluster with multiple nodes. Kind cluster gives a similar experience as a production Kubernetes cluster on your local desktop.
  2. Setup a simple ingress routing using Nginx ingress controller.
  3. Introduce TLS encryption to ingress routing.
  4. Compare the Network policies between Cilium CNI and Kubernetes CNI.
  5. Discuss some of the advantages using Cilium as CNI in networking, observability and service mesh.

Create Kubernetes KinD cluster locally

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
apiVersion: kind.x-k8s.io/v1alpha4
kind: Cluster
name: dev
nodes:
  - role: control-plane
    kubeadmConfigPatches:
      - |
        kind: InitConfiguration
        nodeRegistration:
          kubeletExtraArgs:
            node-labels: "ingress-ready=true"
    extraPortMappings:
      - containerPort: 80
        hostPort: 80
        protocol: TCP
      - containerPort: 443
        hostPort: 443
        protocol: TCP
  - role: worker
  - role: worker

Ingress Routing with Nginx Controller

Application deployment and a service

Ingress Resource

Local DNS mapping and Test the APP

1
2
3
    - Update the file /etc/hosts to create a record: 127.0.0.1 myapp.local

    - test it: curl http://example.local -v

TLS enabled Ingress Resource

Self Signed certificates

Real production workloads will always be encrypted with Certificate Authority (CA) signed TLS certificates. Here lets create self-signed certificates using using OpenSSL tool. This certificate will enable TLS encryption with ingress routing.

Kubernetes Secret

A Kubernetes secret for TLS is required. Lets create one.

1
    - kubectl create secret tls my-secret --cert=tls.crt --key=ingress-tls.key

Desktop View

Enable TLS in Ingress Reource

Network Security with Cilium CNI (Container Networking Interface)

1
2
3
4
    - Cilium is lightweight, best performed CNI and is eBPF based that works directly with Linux Kernel to will eliminate sidecar and kube-proxy.
    - Cilium is best suited for Layer 3/4 and Layer 7 network policies. Other CNIs like Calico, AzureCNI only support Layer 3/4 policies.
    - Observabilty with Hubble with live monitoring of traffic - May not matured compare to istio or Prometheus/ Grafana based monitoring.
    - Cilium can also used as ServiceMesh for traffic routing. However, Istio is still preferred for rich features, complex and multi-cluster routing, secure pod-to-pod communication using mTLS.
1
2
3
4
5
6
7
8
9
apiVersion: kind.x-k8s.io/v1alpha4
kind: Cluster
name: cilium-cluster
nodes:
  - role: control-plane
  - role: worker
  - role: worker
networking:
  disableDefaultCNI: true

Compare network policies

1
2
3
4
5
6
7
8
9
10
apiVersion: "cilium.io/v2"
kind: CiliumNetworkPolicy
metadata:
  name: deny-all-egress
  namespace: default
spec:
  endpointSelector: {} # Match all pods in the default namespace
  egressDeny:
    - toEntities:
        - all # Deny all egress traffic to all destinations

References

https://dev.to/iamunnip/kind-setting-up-cni-using-calico-part-7-31p2