Imagine you have 2 variables. 1 for each team. Both of those are global variables named for example red_team and blue_team. Then you will have code that goes something like this: If player tries to join to red team (by clicking on item, sign, using chat command, etc) check If Variable red_team is larger then blue_team. If it is larger send notification to player that team is full or whatever you wish to do in this case. Else allow player to join red team and increase variable red_team by 1. Same thing you need to do with blue team. Now there is a lot of other things you must code to make this work properly like for example you need to reset these variables when game is finished and to decrease them by 1 when players die or leave game.
Coding teams and queues should be easy but it requires a lot of thinking and testing what could happen in certain cases and way of coding it depends on lot of factors.
I have answered just on your question how to balance teams and with this balance will be +-1 player in team if total of players who want to join is odd number. If it is even number than teams will have same number of players.