Well, there are various ways to deal with the boundary pixels in the image. A common one is to pad the image matrix with an additional line and column in order to have neighbors for those boundary pixels (neighbors that are needed in the kernel convolution operation).
For example, you have this n x n image matrix:
a[0][0] a[0][1] ... a[0][n-1]
a[1][0] a[1][1] ... a[1][n-1]
. . .
. . .
. . .
a[n-1][0] a[n-1][1] ... a[n-1][n-1]
You should pad it by putting the first line below the nth line and the nth line above the first line. Also, the first column is copied after the last column and the last column before the first one.
a[n-1][n-1] a[n-1][0] a[n-1][1] ... a[n-1][n-1] a[n-1][0]
a[0][n-1] a[0][0] a[0][1] ... a[0][n-1] a[0][0]
a[1][n-1] a[1][0] a[1][1] ... a[1][n-1] a[1][0]
. . . . .
. . . . .
. . . . .
a[n-1][n-1] a[n-1][0] a[n-1][1] ... a[n-1][n-1] a[n-1][0]
a[0][n-1] a[0][0] a[0][1] ... a[0][n-1] a[0][0]
As you can see, the corners are reflected in a symmetric way. The top left corner of the new border takes the value of the bottom right element in the initial matrix.
You end up with a (n+2) x (n+2) matrix on which you apply the kernel convolution operation.