Relation between rank and number of distinct eigenvalues

Take for example the matrix $A= \begin{bmatrix} 1 & 0 & 0 \\ 0 & 2 & 0 \\0 & 0 & 0 \end{bmatrix}$, its rank is obviously $2$, eigenvalues are distinct and are $0,1,2$.
We have theorem which says that if eigenvalues are distinct then their eigenvectors must be linearly independent, but the rank of the matrix is $n-1$ if one of this eigenvalues is zero.

Edit after question edit

To answer more generally we need Jordan forms.

Let $A$ be $n$-dimensional square matrix with $n-k$ non-zero eigenvalues
(I don't make here a distinction between all different values and repeated- if all are distinct then there are $n-k$ values , if some are with multiplicities then summarize their number with multiplicities to make full sum $n-k$) and $k$ zero eigenvalues.

Express $A$ through similarity with the Jordan normal form $A=PJP^{-1}$. The matrix $J$ can be presented as composition $J= \begin{bmatrix} J_n & 0 \\0 & J_z \end{bmatrix}$ where $J_n$ is a square part of Jordan matrix with $n-k$ non-zero values (which are eigenvalues) on diagonal and $J_z$ is a square part of Jordan matrix with $k$ zero values on its diagonal.

It is clear that because on the diagonal of upper-triangular matrix $J_n$ are non-zero values and the determinant as the product of these values is non-zero so $J_n$ has full rank i.e. $n-k$.

The rank of $J_z$ depends on the detailed form of this matrix and it can be from $0$ (when $J_z=0$) to $k-1$ ( see examples in comments). It can't be $k$ because $J_z$ is singular.

Therefore the final rank of $J$ can be from $n-k$ to $n-1$.
Similarity preserves rank so the rank of $A$ can be also from $n-k$ to $n-1$.


If the linear transformation has eigen-vectors with distinct eigenvalues, then they are linearly independent(check it, it's easy). Therefore, we know that $\lambda_1u $, $\lambda_2v\in Im(T)$, where $u$ and $v$ are the eigenvectors. Since they are non-zero and linearly independent (the fact that they are multiplied by constants does not change it) we know that $dim(Im(T)) \geq 2$.