How can I create an entity bundle programmatically? Given a custom defined entity 'Foo', how can I make a bundle programmatically?

Such as Node entity has the Article and Basic page bundles (with fields) on install.
Bundles are configuration.

You define a config entity with the name of the bundle of the custom entity:

class FooType extends ConfigEntityBundleBase


Then you can create a new bundle:

$bundle = FooType::create([
  'id' =&gt; 'newbundle',
  'label' =&gt; 'New Bundle',
  'revision' =&gt; FALSE,
]);
$bundle-&gt;save();


Bundles usually are not created programmatically. Most times modules put bundles in /config/install as yml files.