What are the differences between accessing a Kubernetes container via SSH using `ssh` and `kubectl exec`?

Access using ssh Access using kubectl exec
Method Uses standard SSH protocol Uses Kubernetes API
Requirement SSH server must be running inside the container No need for an SSH server
Authentication Requires SSH keys or passwords Uses Kubernetes cluster credentials
Network access SSH port must be exposed and accessible No need to expose ports; works within the cluster
Security Higher risk due to exposed SSH port Lower risk as it uses cluster-internal communication
Complexity More complex setup and configuration Simpler to use; requires only kubectl
Use case For scenarios needing direct SSH access For debugging and management tasks
Performance May have network latency Generally faster due to cluster-internal access
Auditability SSH sessions may not be logged in cluster logs Commands are logged via Kubernetes auditing
File Transfer (SFTP) Supports SFTP and file transfers via clients like FileZilla Does not support SFTP or file transfer protocols

How do I enable SSH access via ssh (instead of kubectl exec) to a container in Kubernetes?