Bite-Sized Kubernetes Part 6 - Ingress, Volumes, Namespaces & Clusters
Tags: kubernetes, devops, containers
Published: 2023-03-09 22:07:10

## Land Ahoy!☸️

You made it! Land in sight!🏝️
In the last part we learnt about services in kubernetes.
In this final part of the series, we shall be exploring **Ingress**, **Volumes** and **Namespaces**! We shall also briefly revisit **Clusters** since you already learnt what they are in [Part 1](https://dev.to/espelar-dev/bite-sized-kubernetes-part-1-introduction-overview-k38)!

<table>
<tr><th>OBJECT</th><th>DESCRIPTION</th></tr>
<tr><td>Pods</td><td>The lowest level, single instance of an application</td></tr>
<tr><td>ReplicaSets</td><td>The next level, manages a set of pods</td></tr>
<tr><td>Deployments</td><td>The next level, manages a set of ReplicaSets</td></tr>
<tr><td>Services</td><td>The next level, manages a set of deployments</td></tr>
<tr><td>👉 Ingress</td><td>The next level, manages a set of services</td></tr>
<tr><td>👉 Volumes</td><td>The next level, manages a set of ingress</td></tr>
<tr><td>👉 Namespaces</td><td>The next level, manages a set of volumes</td></tr>
<tr><td>👉 Cluster</td><td>The highest level, manages a set of namespaces</td></tr>
</table>

## Ingress:
- Ingress is a set of rules that allow external traffic to reach the cluster services.
- Creating ingress:
  - Example `ingress-definition.yml`:
        ```yaml
        apiVersion: extensions/v1beta1
        kind: Ingress
        metadata:
          name: my-app-ingress
        spec:
          rules:
            - host: myapp.com
              http:
                paths:
                  - path: /
                    backend:
                      serviceName: my-app-service
                      servicePort: 80
        ```
  - The `host` property is the domain name that the ingress will listen for requests on.
  - The `path` property is the path that the ingress will listen for requests on.
  - The `serviceName` property is the name of the service that the ingress will forward requests to.
  - The `servicePort` property is the port on the service that the ingress will forward requests to.
  - Once the .yml file is created, it can be used to create an ingress:
        ```bash
        $ kubectl create -f <file name>.yml
        ```
  - See list of ingresses:
        ```bash
        $ kubectl get ingresses
        ```
  - See detailed info about an ingress:
        ```bash
        $ kubectl describe ingress <ingress name>
        ```
  - To access the ingress from outside the cluster, use the node IP address and the node port:
        ```bash
        $ curl <node IP address>:<node port>
        ```
  - To access the ingress from inside the cluster, use the cluster IP address and the port:
        ```bash
        $ curl <cluster IP address>:<port>
        ```

## Volumes:
- Volumes are used to store data that is not ephemeral.
- Volumes are created in the cluster and are mounted to the pods.
- Types of volumes:
  - EmptyDir: a temporary volume that is created when a pod is created and is deleted when the pod is deleted.
  - HostPath: a volume that is mounted from the host machine to the pod.
  - PersistentVolume: a volume that is created in the cluster and is mounted to the pods.
  - PersistentVolumeClaim: a claim for a persistent volume.
- Creating a volume:
  - Example `volume-definition.yml`:
        ```yaml
        apiVersion: v1
        kind: PersistentVolume
        metadata:
          name: my-app-volume
        spec:
          capacity:
            storage: 1Gi
          accessModes:
            - ReadWriteOnce
          hostPath:
            path: /data/my-app
        ```
  - The `capacity` property is the size of the volume.
  - The `accessModes` property is the access mode of the volume.
  - The `hostPath` property is the path on the host machine where the volume will be created.
  - Once the .yml file is created, it can be used to create a volume:
        ```bash
        $ kubectl create -f <file name>.yml
        ```
  - See list of volumes:
        ```bash
        $ kubectl get pv
        ```
  - See detailed info about a volume:
        ```bash
        $ kubectl describe pv <volume name>
        ```

## Namespaces:
- Namespaces are used to isolate resources in the cluster.
- Namespaces are created in the cluster and are used to group resources.
- Creating a namespace:
  - Example `namespace-definition.yml`:
        ```yaml
        apiVersion: v1
        kind: Namespace
        metadata:
          name: my-app-namespace
        ```
  - Once the .yml file is created, it can be used to create a namespace:
        ```bash
        $ kubectl create -f <file name>.yml
        ```
  - See list of namespaces:
        ```bash
        $ kubectl get namespaces
        ```
  - See detailed info about a namespace:
        ```bash
        $ kubectl describe namespace <namespace name>
        ```

## Clusters:
- We have already understood clusters at the very beginning of this blog series.
- A cluster is just a set of nodes (machines) that run containerized applications i.e. k8s pods.
- A cluster can be created using a cloud provider or using a single node.
- Try creating cluster and playing around with it on your local machine using **[minikube](https://minikube.sigs.k8s.io/docs/start/)** or **[kubeadm](https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/create-cluster-kubeadm/)** or you can get started with the services offered by cloud providers like AWS (**[EKS](https://aws.amazon.com/eks/)**), GCP (**[GKE](https://cloud.google.com/kubernetes-engine)**) or Azure (**[AKS](https://azure.microsoft.com/en-us/products/kubernetes-service)**).

Well done and hearty congratulations Sailor!!!🥁📯
You are hereby commissioned Ensign and are now ready to join the fleet!🎖️🎖️🎖️
To be an explorer and a force for good! To venture out into the great sea!🌅 To fight monsters 🦑 and explore uncharted lands!🏞️

Hope this series was fun!
Feel free to check the references below to take your journey of building with Kubernetes further ahead and put your newly acquired skills to the test!
Cheers and until next time!🍻

## References:
- [Kubernetes documentation](https://kubernetes.io/docs/home/)
- [Kubernetes concepts](https://kubernetes.io/docs/concepts/)
- [Kubernetes tutorials](https://kubernetes.io/docs/tutorials/)
- [Kubernetes video courses](https://kodekloud.com/)
- [Kubernetes examples](https://kubernetes.io/docs/concepts/workloads/controllers/deployment/)
- [Kubernetes cheat sheet](https://kubernetes.io/docs/reference/kubectl/cheatsheet/)