Can your landlord evict you if you file for bankruptcy?
No! Your landlord will probably not even know that you filed and if he did you are protected by law. A landlord cannot legally evict a tenant for filing bankruptcy. If you file bankruptcy and then try to move in a landlord can keep you out only if he has a policy that every prospective tenant has to follow where he will not rent to bankruptcy filers. But if you are already in your rental unit and you then file bankruptcy then you are protected by law and the landlord cannot evict you for filing.
Probably though he will never even find out that you filed for bankruptcy. It is only if you have a unexpired lease for any amount of time that he would be notified of your filing. If you are month to month then your landlord won't be notified. But if the landlord somehow finds out about your bankruptcy or he is notified directly because of an ongoing lease he still cannot evict you. If your landlord tries to evict you after a bankruptcy and because of the bankruptcy then you can fight the eviction in California. I believe other states have similar defenses to unlawful evictions.
Remember that you have a federal legal right to file for bankruptcy. No landlord can challenge that or take it away or discriminate against you for exercising your legal federal right to get a fresh start with our debts! If the landlord is smart he will see that you can now pay rent more easily as you will have discharged your credit card, medical, deficiency balance, and other debts in the bankruptcy which will free up more income to pay for rent and your other necessities. You may get a landlord that does not care or even is happy that you filed.
But either way don't be intimidated by a landlord who threatens an eviction. You can fight the eviction and win if the reason he is evicting you is because you filed for bankruptcy.