Time-Sensitive Networking (TSN) evolves from Ethernet AVB in which the Credit-Based Shaping (CBS) is employed to guarantee the deterministic transmission of traffic. In CBS, the real-time performance of traffic associated with the credits can practicably settle the uncertainty of queueing and forwarding for stream-reservation traffic. Hence, the optimization of bandwidth allocation under the CBS becomes a key point to ensure guaranteed performance in the network. In this paper, a bandwidth allocation method is proposed for stream-reservation traffic while the real-time requirements are satisfied. We first illustrate the significance of appropriate bandwidth allocation for traffic under the CBS and construct a general schema for its bandwidth allocation. Also, the influences of the protected window for Control Data Traffic (CDT) on stream-reservation traffic are considered in our method. Further, mathematical models are constructed to analyze the delay bounds and backlogs of traffic to form the feedback for the optimal bandwidth allocation process. Finally, two node-level cases with different bandwidth utilization and a synthetic industrial networking scenario are carried out to demonstrate our method. The results confirm that the excessive reserved bandwidth does not necessarily decrease the delay bound, especially under the high traffic loads scenario. A more desirable bandwidth allocation strategy under the CBS mechanism is that the reserved bandwidth should be just enough according to the traffic loads to ensure the deterministic transmission of traffic.