This paper presents a data-driven method for designing optimal controllers and robust controllers for unknown nonlinear systems. Mathematical models for the realization of the control are difficult to develop owing to a lack of knowledge regarding such systems. The proposed multidisciplinary method, based on optimal control theory and machine learning with kernel functions, facilitates designing appropriate controllers using a data set. Kernel-based system models are useful for representing nonlinear systems. An optimal and an H-infinity controller can be designed by solving Hamilton-Jacobi (HJ) equations, which unfortunately, are difficult to solve owing to the nonlinearity and complexity of the kernelbased models. The objective of this study consists of overcoming two challenges. The first challenge is to derive exact solutions to the HJ equations for a class of kernel-based system models. A key technique in overcoming this challenge is to reduce the HJ equations to easily solvable algebraic matrix equations, from which optimal and H-infinity controllers are designed. The second challenge is to control an unknown system using the obtained controllers, wherein the system is identified as a kernel-based model. Additionally, this study analyzes probabilistic stability of the feedback system with the proposed controllers. Numerical simulations demonstrate control performances of both the derived optimal and Hinfinity controllers and stability of the feedback system.