Osteoarthritis (OA) is a chronic degenerative disease of the bone and joints. Immune-related genes and immune cell infiltration are important in OA development. We analyzed immune-related genes and immune infiltrates to identify OA diagnostic markers. The datasets GSE51588, GSE55235, GSE55457, GSE82107, and GSE114007 were downloaded from the Gene Expression Omnibus database. First, R software was used to identify differentially expressed genes (DEGs) and differentially expressed immune-related genes (DEIRGs), and functional correlation analysis was conducted. Second, CIBERSORT was used to evaluate infiltration of immune cells in OA tissue. Finally, the least absolute shrinkage and selection operator logistic regression algorithm and support vector machine-recurrent feature elimination algorithm were used to screen and verify diagnostic markers of OA. A total of 711 DEGs and 270 DEIRGs were identified in this study. Functional enrichment analysis showed that the DEGs and DEIRGs are closely related to cellular calcium ion homeostasis, ion channel complexes, chemokine signaling pathways, and JAK-STAT signaling pathways. Differential analysis of immune cell infiltration showed that M1 macrophage infiltration was increased but that mast cell and neutrophil infiltration were decreased in OA samples. The machine learning algorithm cross-identified 15 biomarkers (BTC, PSMD8, TLR3, IL7, APOD, CIITA, IFIH1, CDC42, FGF9, TNFAIP3, CX3CR1, ERAP2, SEMA3D, MPO, and plasma cells). According to pass validation, all 15 biomarkers had high diagnostic efficacy (AUC > 0.7), and the diagnostic efficiency was higher when the 15 biomarkers were fitted into one variable (AUC = 0.758). We developed 15 biomarkers for OA diagnosis. The findings provide a new understanding of the molecular mechanism of OA from the perspective of immunology.