Some about the $SU(3)$ algebra
First, note that $SU(3)$ group algebra has two Casimir operators in covering group, namely,
$$
C_{1}= \sum_{i}t_{i}t_{i}, \quad C_{2} = \sum_{i,j,k}d_{ijk}t_{i}t_{j}t_{k},
$$
where $t_{i}, i = 1,...,8$ are Gell-Mann matrices and $d_{ijk}$ is defined as
$$
\{t_{i},t_{j}\} = \frac{1}{3}\delta_{ij}+d_{ijk}t_{k}
$$
This means that each irreducible representation of the $SU(3)$ group is characterized by two numbers.
Let's define these numbers. Precisely, let's introduce new generators:
$$
\tag 0 I_{\pm}=t_{1}\pm it_{2}, \quad I_{3} = t_{3}, \quad V_{\pm} =t_4 \pm it_5, \quad U_{\pm} = t_6 \pm it_7, Y =\frac{2}{\sqrt{3}}t_8
$$
Two generators $Y, I_{3}$ commute and thus have the same set of eigenstates (other combinations will be used below).
Let's write these eigenstates as $|m,y\rangle$ (Note that here and everywhere below I neglect the physical spin part of the state). We have
$$
I_{3}|m,y\rangle = m |m,y\rangle , \quad Y|m,y\rangle = y|m,y\rangle
$$
Note that there is a linear relation between $I_{3}, Y$ called Gell-Mann-Nishijima formula:
$$
\tag 1 Q = I_{3} +\frac{Y}{2},
$$
where $Q$ is electric charge, and also
$$
\tag 2 Y = B+S,
$$
where $B$ is the baryon number and $S$ is the strangeness.
Constructing the quarks states
Let's now construct the quark states in the space of the generators $t$. Each quark has the baryon number $B=\frac{1}{3}$; u-quark has electric charge $Q=\frac{2}{3}$, while $s-,d-$quarks have $Q=-\frac{1}{3}$; finally, the strangeness of $s$-quark is $S=-1$, while the strangeness of $u-,d$-quarks are zero. By using $(1),(2)$ we have that $u$-quark has $Y = \frac{1}{3}, I_{3} = \frac{1}{2}$, $d$-quark has $Y=\frac{1}{3}, I_{3}=-\frac{1}{2}$, while $s$-quark has $Y=-\frac{2}{3}, I_{3}=0$ (note that in fact the quantum number of quarks like charge and the baryon number were historically determined by knowing the quantum numbers of mesons and other bounded states, see the answer).
By using explicit form of Gell-Mann matrices, You can construct corresponding states:
$$
u = \begin{pmatrix} 1\\ 0 \\ 0\end{pmatrix}, \quad d = \begin{pmatrix} 0\\ 1 \\ 0\end{pmatrix}, \quad u = \begin{pmatrix} 0\\ 0 \\ 1\end{pmatrix}
$$
Completely analogically You can define the antiquarks states. Corresponding generators have the form $\bar{t}_{i}= -t_{i}^{*}$, so the numbers $m, y$ for them are with different sign.
Mesons states
Next, suppose the product $3\times \bar{3} = 8\oplus 1$. This product contains the states $u\bar{s}, s\bar{u}, s\bar{d}, d\bar{s},u\bar{d}, d\bar{u}$ with non-zero numbers $y,m$ and three linearly independent combinations $u\bar{u}, d\bar{d}, s\bar{s}$ with zero $m,y$. One of these three states is the $SU(3)$ singlet. Note that all of these nine states have zero baryon number. By calculating the quantum numbers (strangeness, charge, isospin) of first six states You can identify them as $K^{\pm}, K^{0}, \bar{K}^{0}, \pi^{\pm}$ mesons. The last three states are $\eta, \pi^{0},\eta'$.
Let's construct the states $\eta, \pi^{0},\eta'$. What do we know about them? For example, the facts that $\pi^{0}$ form the isospin triplet (together with $\pi^{\pm}$) and must have $I_{3} = 0$ (for the fixed value of $y$), while $\eta'$ is the $SU(3)$ singlet. This is enough for constructing of all states.
We know that $\pi^{-}$ is identified with the state $|I_{3} = -1, Y = 1\rangle$. By using algebra of Gell-Mann matrices we know that $I_{+}|m,y\rangle = \sqrt{2}|m+1,y\rangle$ (for the given representation $3$). Therefore the $\pi^{0}$ is can be identified with $\frac{1}{\sqrt{2}}I_{3}\pi^{-}$:
$$
\tag 3 \pi^{0} = \frac{1}{\sqrt{2}}I_{+}\pi^{-} \equiv \frac{1}{\sqrt{2}}(I_{+}^{3} + I_{+}^{\bar{3}})d\bar{u} = \frac{1}{\sqrt{2}}(u\bar{u} - d\bar{d})
$$
As for $\eta'$, let's define it as
$$
\eta' = \alpha u\bar{u} + \beta d\bar{d} + \gamma s\bar{s}
$$
It is the singlet, so action of all of lowering-uppering operators $U_{\pm}, V_{\pm}, I_{\pm}$ from $(1)$ on it must give zero. We thus obtain
$$
\tag 4 \eta' = \frac{1}{\sqrt{3}}(u\bar{u} + d\bar{d} + s\bar{s})
$$
Finally, let's find $\eta^{0}$ by requiring its state to be orthogonal to $(3),(4)$. By using $\langle q_{i}| q_{j}\rangle = \langle \bar{q}_{i}|\bar{q}_{j}\rangle = \delta_{ij}$, one obtains
$$
\eta^{0} = \frac{1}{\sqrt{6}}(u\bar{u} + d\bar{d} - 2s\bar{s})
$$