> ## Documentation Index
> Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Exploring the Open Cluster Hands On

> Hands-on Kubernetes guide exploring Deployments, Services, pod-to-pod connectivity, testing access to a MySQL service, and using NetworkPolicies and CNIs to enforce isolation.

Bob opens a terminal on his cluster and walks through a few practical questions to understand resource exposure and pod-to-pod connectivity.

## 1) How many Deployments are in the `default` namespace?

He lists Deployments and sees a single Deployment, `deploy-a`. The other pods (pod-b and the MySQL pod) were created directly (not managed by a Deployment), so the answer is 1.

```bash theme={null}
$ kubectl get deployments
NAME      READY   UP-TO-DATE   AVAILABLE   AGE
deploy-a  1/1     1            1           22m
```

## 2) How is `deploy-a` exposed? How does a Service select backend pods?

Services select backend pods using label selectors (small key/value pairs attached to objects). Bob lists Services to see what exists in the cluster.

```bash theme={null}
$ kubectl get svc
NAME                TYPE        CLUSTER-IP       PORT(S)
conntest-service    NodePort    10.104.37.120    8080:30082/TCP
db-service          ClusterIP   10.97.205.252    3306/TCP
kubernetes          ClusterIP   10.96.0.1        443/TCP
service-a           ClusterIP   10.99.96.196     80/TCP
service-b           ClusterIP   10.98.140.156    80/TCP
```

service-a is a `ClusterIP` service on port `80` (accessible only from within the cluster). To confirm that `service-a` fronts `deploy-a`, Bob inspects the Service selector and compares it with pod labels:

```bash theme={null}
$ kubectl describe svc service-a
# (output omitted here — this shows the selector used by service-a)
```

```bash theme={null}
$ kubectl get pods --show-labels
NAME                        LABELS
connection-tester           name=connection-tester
deploy-a-7db64d64cf-cv8w6   app=deployA,pod-template-hash=7db64d64cf
mysql                       name=mysql
pod-b                       run=pod-b
```

`deploy-a`'s pod carries the label `app=deployA`, which matches `service-a`'s selector. Therefore, `deploy-a` is exposed through `service-a` (a `ClusterIP` service).

### Quick reference — Services in this cluster

| Service | Type | Cluster IP | Port(s) | Selector |
| -: | - | -: | -: | - |
| `conntest-service` | NodePort | `10.104.37.120` | `8080:30082/TCP` | (not shown) |
| `db-service` | ClusterIP | `10.97.205.252` | `3306/TCP` | (not shown) |
| `service-a` | ClusterIP | `10.99.96.196` | `80/TCP` | matches `app=deployA` |
| `service-b` | ClusterIP | `10.98.140.156` | `80/TCP` | matches `run=pod-b` |

## 3) Which port does `service-b` expose?

Bob describes `service-b` to read the port, selector, and endpoints. The important lines show port `80/TCP`, selector `run=pod-b`, and the Pod endpoint IP:port.

```bash theme={null}
$ kubectl describe service service-b
Name:                     service-b
Namespace:                default
Labels:                   run=pod-b
Annotations:              <none>
Selector:                 run=pod-b
Type:                     ClusterIP
IP:                       10.98.140.156
IPs:                      10.98.140.156
Port:                     <unset>  80/TCP
TargetPort:               80/TCP
Endpoints:                10.244.192.2:80
Session Affinity:         None
Events:                   <none>
```

Because the `Endpoints` entry points to the `pod-b` IP on port 80, `service-b` forwards traffic to `pod-b` on port 80.

## 4) Can `deploy-a` reach the MySQL database (`db-service`)?

Deployments add a generated suffix to pod names, so Bob lists pods, copies the full pod name for `deploy-a`, and then checks connectivity from inside that pod using `nc` (netcat).

* `-z` scans for listening daemons without sending data.
* `-v` enables verbose output.

```bash theme={null}
$ kubectl get pods
NAME                          READY   STATUS    RESTARTS   AGE
connection-tester             1/1     Running   0          22m
deploy-a-7db64d64cf-cv8w6     1/1     Running   0          22m
mysql                         1/1     Running   0          22m
pod-b                         1/1     Running   0          22m

$ kubectl exec -it deploy-a-7db64d64cf-cv8w6 -- nc -zv db-service 3306
db-service (10.97.205.252:3306) open
```

The output shows the TCP port is open — `deploy-a` can reach `db-service` on port `3306`. Using `telnet` inside the pod illustrates the MySQL handshake as well (the response contains non-printable characters and the server version):

```bash theme={null}
$ kubectl exec -it deploy-a-7db64d64cf-cv8w6 -- bash
bash-5.1# telnet db-service 3306
Connected to db-service
J
8.0.33 ^G6m%Y)R>Lr8+QgM;|caching_sha2_password
```

## 5) What about `pod-b`? Should it reach the database?

Bob runs the same connectivity check from `pod-b` (which has no intended reason to access the database):

```bash theme={null}
$ kubectl exec pod-b -- nc -zv db-service 3306
db-service (10.97.205.252:3306) open
```

`pod-b` can also connect to MySQL. This is expected behavior in a default Kubernetes installation: all pods can talk to all other pods unless network isolation is explicitly configured.

A secure posture typically follows least privilege: allow `deploy-a` to access the database while blocking unnecessary access from `pod-b`. The Kubernetes primitive used to implement this restriction is a NetworkPolicy — but creating the YAML is only part of what’s required.

![A stylized Kubernetes diagram showing three pods labeled deploy-a, pod-b, and mysql inside the default namespace, with a NetworkPolicy permitting deploy-a to reach the MySQL pod/service (port 3306) while pod-b is blocked.](https://mintcdn.com/kodekloud-c4ac6d9a/UCHQITKCSrYPqxtk/images/Learn-By-Doing-Kubernetes-Network-Policies/Why-Network-Policies/Exploring-the-Open-Cluster-Hands-On/k8s-networkpolicy-allow-deploya-mysql.jpg?fit=max\&auto=format\&n=UCHQITKCSrYPqxtk\&q=85\&s=a384243a025344900a5b56f11c597088)

A NetworkPolicy is just a Kubernetes object (YAML) that describes allowed traffic. Storing a NetworkPolicy object in the API server does not itself drop traffic — the cluster's network plugin (CNI) must implement and enforce NetworkPolicies by programming rules on each node.

By default, Kubernetes is permissive: all pods can talk to all pods. To enforce isolation you must both create [NetworkPolicies](https://kubernetes.io/docs/concepts/services-networking/network-policies/) and use a CNI that implements them (for example, [Calico](https://projectcalico.docs.tigera.io/), [Cilium](https://cilium.io/), or other policy-capable CNIs).

## Further reading and references

* Kubernetes Network Policies — [https://kubernetes.io/docs/concepts/services-networking/network-policies/](https://kubernetes.io/docs/concepts/services-networking/network-policies/)
* Project Calico — [https://projectcalico.docs.tigera.io/](https://projectcalico.docs.tigera.io/)
* Cilium — [https://cilium.io/](https://cilium.io/)

> [card] [Watch Video](https://learn.kodekloud.com/user/courses/learn-by-doing-kubernetes-network-policies/module/6512e13a-f8c1-44ec-a8da-8a58f927b32e/lesson/486b7adc-d6bd-478e-9125-2183b51f346c)

> [card] [Practice Lab](https://learn.kodekloud.com/user/courses/learn-by-doing-kubernetes-network-policies/module/6512e13a-f8c1-44ec-a8da-8a58f927b32e/lesson/e5a3a627-cedc-4c1e-9d31-8ad6c8802bbc)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.