or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

backup-services.mdcompute-services.mdcontainer-services.mdcore-driver-system.mddns-management.mdindex.mdload-balancer-services.mdstorage-services.md

container-services.mddocs/

0

# Container Services

1

2

The container service provides a unified interface for container and cluster management across multiple container platforms including Kubernetes, Docker, AWS ECS, Google Container Engine, Azure Container Service, and others.

3

4

## Providers

5

6

```python { .api }

7

from libcloud.container.types import Provider

8

9

class Provider:

10

"""Enumeration of supported container providers"""

11

DOCKER = 'docker' # Docker Engine

12

KUBERNETES = 'kubernetes' # Kubernetes clusters

13

ECS = 'ecs' # AWS Elastic Container Service

14

GKE = 'gke' # Google Kubernetes Engine

15

AKS = 'aks' # Azure Kubernetes Service

16

RANCHERK8S = 'rancherk8s' # Rancher Kubernetes

17

LXD = 'lxd' # LXD containers

18

DIMENSIONDATA = 'dimensiondata' # Dimension Data containers

19

JOYENT = 'joyent' # Joyent Triton

20

# ... more providers

21

```

22

23

## Driver Factory

24

25

```python { .api }

26

from libcloud.container.providers import get_driver

27

28

def get_driver(provider: Provider) -> type[ContainerDriver]

29

```

30

31

Get the driver class for a specific container provider.

32

33

**Parameters:**

34

- `provider`: Provider identifier from the Provider enum

35

36

**Returns:**

37

- Driver class for the specified provider

38

39

**Example:**

40

```python

41

from libcloud.container.types import Provider

42

from libcloud.container.providers import get_driver

43

44

# Get Kubernetes driver class

45

cls = get_driver(Provider.KUBERNETES)

46

47

# Initialize driver with credentials

48

driver = cls('api_server_url', key='api_token')

49

```

50

51

## Core Classes

52

53

### ContainerDriver

54

55

```python { .api }

56

class ContainerDriver(BaseDriver):

57

"""Base class for all container drivers"""

58

59

def list_containers(self, image: ContainerImage = None, all: bool = True) -> List[Container]

60

def get_container(self, id: str) -> Container

61

def start_container(self, container: Container) -> Container

62

def stop_container(self, container: Container) -> Container

63

def restart_container(self, container: Container) -> Container

64

def destroy_container(self, container: Container) -> bool

65

def deploy_container(self, name: str, image: ContainerImage, cluster: ContainerCluster = None, **kwargs) -> Container

66

def list_images(self) -> List[ContainerImage]

67

def install_image(self, path: str) -> ContainerImage

68

def list_clusters(self) -> List[ContainerCluster]

69

def get_cluster(self, id: str) -> ContainerCluster

70

def create_cluster(self, name: str, **kwargs) -> ContainerCluster

71

def destroy_cluster(self, cluster: ContainerCluster) -> bool

72

def ex_list_cluster_nodes(self, cluster: ContainerCluster) -> List[Dict]

73

```

74

75

Base class that all container drivers inherit from. Provides methods for managing containers, images, and clusters.

76

77

**Key Methods:**

78

79

- `list_containers()`: List all containers

80

- `deploy_container()`: Deploy a new container

81

- `start_container()`: Start a stopped container

82

- `stop_container()`: Stop a running container

83

- `destroy_container()`: Remove a container

84

- `list_clusters()`: List container clusters

85

- `create_cluster()`: Create a new cluster

86

87

### Container

88

89

```python { .api }

90

class Container:

91

"""Represents a container instance"""

92

93

id: str

94

name: str

95

image: ContainerImage

96

state: ContainerState

97

ip_addresses: List[str]

98

driver: ContainerDriver

99

extra: Dict[str, Any]

100

101

def start(self) -> Container

102

def stop(self) -> Container

103

def restart(self) -> Container

104

def destroy(self) -> bool

105

def get_logs(self) -> str

106

```

107

108

Represents a container instance.

109

110

**Properties:**

111

- `id`: Unique container identifier

112

- `name`: Container name

113

- `image`: Container image used

114

- `state`: Current state (running, stopped, pending, etc.)

115

- `ip_addresses`: List of IP addresses assigned to container

116

- `extra`: Provider-specific metadata (ports, volumes, environment variables, etc.)

117

118

**Methods:**

119

- `start()`: Start this container

120

- `stop()`: Stop this container

121

- `restart()`: Restart this container

122

- `destroy()`: Remove this container

123

- `get_logs()`: Get container logs

124

125

### ContainerImage

126

127

```python { .api }

128

class ContainerImage:

129

"""Represents a container image"""

130

131

id: str

132

name: str

133

tag: str

134

driver: ContainerDriver

135

version: str

136

extra: Dict[str, Any]

137

138

def deploy(self, name: str, cluster: ContainerCluster = None, **kwargs) -> Container

139

```

140

141

Represents a container image that can be used to create containers.

142

143

**Properties:**

144

- `id`: Unique image identifier

145

- `name`: Image name (e.g., "nginx", "ubuntu")

146

- `tag`: Image tag/version (e.g., "latest", "1.21")

147

- `version`: Image version

148

- `extra`: Provider-specific metadata (size, created date, etc.)

149

150

**Methods:**

151

- `deploy()`: Deploy a container from this image

152

153

### ContainerCluster

154

155

```python { .api }

156

class ContainerCluster:

157

"""Represents a container cluster"""

158

159

id: str

160

name: str

161

driver: ContainerDriver

162

state: str

163

extra: Dict[str, Any]

164

165

def list_containers(self) -> List[Container]

166

def deploy_container(self, name: str, image: ContainerImage, **kwargs) -> Container

167

def destroy(self) -> bool

168

```

169

170

Represents a container cluster (e.g., Kubernetes cluster, ECS cluster).

171

172

**Properties:**

173

- `id`: Unique cluster identifier

174

- `name`: Cluster name

175

- `state`: Current state (active, creating, deleting, etc.)

176

- `extra`: Provider-specific metadata (node count, version, etc.)

177

178

**Methods:**

179

- `list_containers()`: List containers in this cluster

180

- `deploy_container()`: Deploy a container to this cluster

181

- `destroy()`: Delete this cluster

182

183

### ContainerState

184

185

```python { .api }

186

class ContainerState:

187

"""Container states enumeration"""

188

RUNNING = 0

189

STOPPED = 1

190

PENDING = 2

191

TERMINATED = 3

192

UNKNOWN = 4

193

ERROR = 5

194

PAUSED = 6

195

SUSPENDED = 7

196

STARTING = 8

197

STOPPING = 9

198

```

199

200

Enumeration of possible container states during their lifecycle.

201

202

## Docker Registry Support

203

204

```python { .api }

205

from libcloud.container.utils.docker import RegistryClient, HubClient

206

207

class RegistryClient:

208

"""Docker registry client"""

209

210

def __init__(self, host: str = 'registry-1.docker.io', port: int = 443, username: str = None, password: str = None)

211

def get_image(self, name: str, tag: str = 'latest') -> Dict

212

def list_images(self) -> List[Dict]

213

def push_image(self, name: str, tag: str = 'latest') -> bool

214

def pull_image(self, name: str, tag: str = 'latest') -> bool

215

216

class HubClient(RegistryClient):

217

"""Docker Hub client"""

218

219

def __init__(self, username: str = None, password: str = None)

220

def get_repository(self, name: str) -> Dict

221

def list_repositories(self, username: str = None) -> List[Dict]

222

```

223

224

Utilities for interacting with Docker registries and Docker Hub.

225

226

## Usage Examples

227

228

### Basic Container Management

229

230

```python

231

from libcloud.container.types import Provider, ContainerState

232

from libcloud.container.providers import get_driver

233

234

# Initialize Docker driver

235

cls = get_driver(Provider.DOCKER)

236

driver = cls(host='unix:///var/run/docker.sock')

237

238

# Alternative: Remote Docker daemon

239

# driver = cls(host='tcp://docker-host:2376', cert_path='/path/to/certs')

240

241

# List existing containers

242

containers = driver.list_containers(all=True) # Include stopped containers

243

for container in containers:

244

print(f"Container: {container.name} ({container.state}) - Image: {container.image.name}")

245

246

# List available images

247

images = driver.list_images()

248

for image in images:

249

print(f"Image: {image.name}:{image.tag} (ID: {image.id[:12]})")

250

251

# Deploy a new container

252

nginx_image = None

253

for image in images:

254

if 'nginx' in image.name:

255

nginx_image = image

256

break

257

258

if nginx_image:

259

container = driver.deploy_container(

260

name='web-server',

261

image=nginx_image,

262

ports=[80, 443],

263

environment={'ENV': 'production'},

264

volumes={'/var/www/html': '/usr/share/nginx/html'}

265

)

266

print(f"Deployed container: {container.name} ({container.id})")

267

```

268

269

### Kubernetes Container Management

270

271

```python

272

# Initialize Kubernetes driver

273

k8s_cls = get_driver(Provider.KUBERNETES)

274

k8s_driver = k8s_cls(

275

host='https://k8s-api-server:6443',

276

key='api_token', # Or use cert_file/key_file for certificate auth

277

ca_cert='/path/to/ca.crt'

278

)

279

280

# List clusters (nodes in Kubernetes context)

281

clusters = k8s_driver.list_clusters()

282

for cluster in clusters:

283

print(f"Cluster: {cluster.name} ({cluster.state})")

284

if cluster.extra:

285

print(f" Nodes: {cluster.extra.get('node_count', 'unknown')}")

286

287

# List pods (containers in Kubernetes)

288

pods = k8s_driver.list_containers()

289

for pod in pods:

290

namespace = pod.extra.get('namespace', 'default')

291

print(f"Pod: {pod.name} in namespace {namespace} ({pod.state})")

292

print(f" Image: {pod.image.name}")

293

print(f" IPs: {pod.ip_addresses}")

294

295

# Deploy a pod

296

pod = k8s_driver.deploy_container(

297

name='web-app',

298

image=ContainerImage(id=None, name='nginx', tag='1.21', driver=k8s_driver),

299

ex_namespace='production',

300

ex_replicas=3,

301

ex_service_ports=[{'port': 80, 'target_port': 80}]

302

)

303

print(f"Deployed pod: {pod.name}")

304

```

305

306

### AWS ECS Container Management

307

308

```python

309

# Initialize ECS driver

310

ecs_cls = get_driver(Provider.ECS)

311

ecs_driver = ecs_cls('access_key', 'secret_key', region='us-east-1')

312

313

# List ECS clusters

314

clusters = ecs_driver.list_clusters()

315

for cluster in clusters:

316

print(f"ECS Cluster: {cluster.name}")

317

print(f" Active Services: {cluster.extra.get('active_services_count', 0)}")

318

print(f" Running Tasks: {cluster.extra.get('running_tasks_count', 0)}")

319

320

# Create a new ECS cluster

321

new_cluster = ecs_driver.create_cluster(

322

name='production-cluster',

323

ex_capacity_providers=['FARGATE', 'EC2']

324

)

325

print(f"Created ECS cluster: {new_cluster.name}")

326

327

# Deploy a task (container) to ECS

328

task = ecs_driver.deploy_container(

329

name='web-service',

330

image=ContainerImage(id=None, name='nginx', tag='latest', driver=ecs_driver),

331

cluster=new_cluster,

332

ex_cpu=256, # 0.25 vCPU

333

ex_memory=512, # 512 MB

334

ex_network_mode='awsvpc',

335

ex_launch_type='FARGATE'

336

)

337

print(f"Deployed ECS task: {task.name}")

338

```

339

340

### Container Lifecycle Management

341

342

```python

343

# Get a specific container

344

container = driver.get_container('container-id-123')

345

print(f"Container state: {container.state}")

346

347

# Start a stopped container

348

if container.state == ContainerState.STOPPED:

349

started_container = container.start()

350

print(f"Started container: {started_container.state}")

351

352

# Stop a running container

353

if container.state == ContainerState.RUNNING:

354

stopped_container = container.stop()

355

print(f"Stopped container: {stopped_container.state}")

356

357

# Restart a container

358

restarted_container = container.restart()

359

print(f"Restarted container: {restarted_container.state}")

360

361

# Get container logs

362

try:

363

logs = container.get_logs()

364

print(f"Container logs:\n{logs}")

365

except AttributeError:

366

print("Log retrieval not supported by this provider")

367

368

# Remove a container

369

success = container.destroy()

370

print(f"Container removed: {success}")

371

```

372

373

### Advanced Container Deployment

374

375

```python

376

def deploy_multi_tier_application(driver, cluster=None):

377

"""Deploy a multi-tier application with database and web components"""

378

379

# Database container

380

db_container = driver.deploy_container(

381

name='app-database',

382

image=ContainerImage(id=None, name='postgres', tag='13', driver=driver),

383

cluster=cluster,

384

environment={

385

'POSTGRES_DB': 'appdb',

386

'POSTGRES_USER': 'appuser',

387

'POSTGRES_PASSWORD': 'secure_password'

388

},

389

volumes={'/var/lib/postgresql/data': '/data/postgres'},

390

ex_restart_policy='always'

391

)

392

print(f"Deployed database: {db_container.name}")

393

394

# Web application container

395

web_container = driver.deploy_container(

396

name='app-web',

397

image=ContainerImage(id=None, name='myapp', tag='v1.0', driver=driver),

398

cluster=cluster,

399

ports=[8080],

400

environment={

401

'DATABASE_URL': f'postgresql://appuser:secure_password@{db_container.name}:5432/appdb',

402

'APP_ENV': 'production'

403

},

404

ex_links=[db_container.name], # Link to database container

405

ex_restart_policy='unless-stopped'

406

)

407

print(f"Deployed web app: {web_container.name}")

408

409

# Load balancer/reverse proxy container

410

proxy_container = driver.deploy_container(

411

name='app-proxy',

412

image=ContainerImage(id=None, name='nginx', tag='alpine', driver=driver),

413

cluster=cluster,

414

ports=[80, 443],

415

volumes={'/etc/nginx/nginx.conf': '/config/nginx.conf'},

416

ex_links=[web_container.name],

417

ex_restart_policy='always'

418

)

419

print(f"Deployed proxy: {proxy_container.name}")

420

421

return [db_container, web_container, proxy_container]

422

423

# Deploy the application

424

app_containers = deploy_multi_tier_application(driver)

425

```

426

427

### Docker Registry Integration

428

429

```python

430

from libcloud.container.utils.docker import RegistryClient, HubClient

431

432

# Connect to Docker Hub

433

hub_client = HubClient(username='myusername', password='mypassword')

434

435

# List repositories

436

repos = hub_client.list_repositories('myusername')

437

for repo in repos:

438

print(f"Repository: {repo['name']} - Stars: {repo.get('star_count', 0)}")

439

440

# Get repository details

441

repo_info = hub_client.get_repository('myusername/myapp')

442

print(f"Repository: {repo_info['name']}")

443

print(f"Description: {repo_info.get('description', 'No description')}")

444

print(f"Last updated: {repo_info.get('last_updated')}")

445

446

# Connect to private registry

447

registry_client = RegistryClient(

448

host='my-registry.company.com',

449

port=443,

450

username='registry_user',

451

password='registry_password'

452

)

453

454

# Pull image from private registry

455

success = registry_client.pull_image('private-app', 'v2.1')

456

print(f"Image pulled: {success}")

457

458

# Push image to private registry

459

success = registry_client.push_image('my-app', 'latest')

460

print(f"Image pushed: {success}")

461

```

462

463

### Container Monitoring and Health Checks

464

465

```python

466

import time

467

from typing import List, Dict

468

469

def monitor_container_health(driver, containers: List[Container], interval: int = 30):

470

"""Monitor container health and restart unhealthy containers"""

471

472

print(f"Monitoring {len(containers)} containers...")

473

474

while True:

475

try:

476

for container in containers:

477

# Refresh container state

478

current_container = driver.get_container(container.id)

479

480

print(f"Container {current_container.name}: {current_container.state}")

481

482

# Check if container should be running but isn't

483

if (current_container.state in [ContainerState.STOPPED, ContainerState.ERROR] and

484

container.extra.get('expected_state') == 'running'):

485

486

print(f"Restarting unhealthy container: {current_container.name}")

487

restarted = current_container.restart()

488

print(f"Restart result: {restarted.state}")

489

490

# Check resource usage if available

491

if 'resource_usage' in current_container.extra:

492

usage = current_container.extra['resource_usage']

493

cpu_percent = usage.get('cpu_percent', 0)

494

memory_percent = usage.get('memory_percent', 0)

495

496

print(f" CPU: {cpu_percent:.1f}%, Memory: {memory_percent:.1f}%")

497

498

# Alert on high resource usage

499

if cpu_percent > 90 or memory_percent > 90:

500

print(f"WARNING: High resource usage in {current_container.name}")

501

502

except Exception as e:

503

print(f"Error monitoring containers: {e}")

504

505

time.sleep(interval)

506

507

def get_container_stats(driver, container: Container) -> Dict:

508

"""Get container resource statistics"""

509

try:

510

# This is provider-specific - Docker example

511

if hasattr(driver, 'ex_get_container_stats'):

512

stats = driver.ex_get_container_stats(container)

513

return {

514

'cpu_usage': stats.get('cpu_usage', {}),

515

'memory_usage': stats.get('memory_usage', {}),

516

'network_io': stats.get('network_io', {}),

517

'block_io': stats.get('block_io', {})

518

}

519

except AttributeError:

520

pass

521

522

return {}

523

524

# Usage

525

important_containers = [container for container in driver.list_containers()

526

if container.state == ContainerState.RUNNING]

527

528

# Get stats for each container

529

for container in important_containers:

530

stats = get_container_stats(driver, container)

531

if stats:

532

print(f"Stats for {container.name}: {stats}")

533

534

# Start monitoring (run in separate thread/process)

535

# monitor_container_health(driver, important_containers, interval=60)

536

```

537

538

### Container Scaling and Load Balancing

539

540

```python

541

def scale_container_service(driver, service_name: str, target_count: int, cluster: ContainerCluster = None):

542

"""Scale a container service up or down"""

543

544

# Get current containers for the service

545

all_containers = driver.list_containers()

546

service_containers = [c for c in all_containers if service_name in c.name]

547

548

current_count = len(service_containers)

549

print(f"Current {service_name} containers: {current_count}, Target: {target_count}")

550

551

if current_count < target_count:

552

# Scale up

553

to_create = target_count - current_count

554

print(f"Scaling up: creating {to_create} new containers")

555

556

# Find a template container to replicate

557

template = service_containers[0] if service_containers else None

558

if not template:

559

print("No template container found for scaling")

560

return

561

562

for i in range(to_create):

563

new_container = driver.deploy_container(

564

name=f"{service_name}-{current_count + i + 1}",

565

image=template.image,

566

cluster=cluster,

567

ports=template.extra.get('ports', []),

568

environment=template.extra.get('environment', {}),

569

volumes=template.extra.get('volumes', {})

570

)

571

print(f"Created container: {new_container.name}")

572

573

elif current_count > target_count:

574

# Scale down

575

to_remove = current_count - target_count

576

print(f"Scaling down: removing {to_remove} containers")

577

578

# Remove excess containers (oldest first)

579

containers_to_remove = service_containers[:to_remove]

580

for container in containers_to_remove:

581

success = container.destroy()

582

print(f"Removed container {container.name}: {success}")

583

584

else:

585

print("Service is already at target scale")

586

587

def create_container_load_balancer(driver, service_containers: List[Container], lb_port: int = 80):

588

"""Create a load balancer container for a service"""

589

590

# Generate nginx configuration for load balancing

591

upstream_servers = []

592

for container in service_containers:

593

if container.ip_addresses:

594

ip = container.ip_addresses[0]

595

port = container.extra.get('exposed_ports', [8080])[0]

596

upstream_servers.append(f"server {ip}:{port};")

597

598

nginx_config = f"""

599

upstream backend {{

600

{chr(10).join(upstream_servers)}

601

}}

602

603

server {{

604

listen {lb_port};

605

location / {{

606

proxy_pass http://backend;

607

proxy_set_header Host $host;

608

proxy_set_header X-Real-IP $remote_addr;

609

}}

610

}}

611

"""

612

613

# Deploy load balancer container

614

lb_container = driver.deploy_container(

615

name='service-load-balancer',

616

image=ContainerImage(id=None, name='nginx', tag='alpine', driver=driver),

617

ports=[lb_port],

618

volumes={'/etc/nginx/conf.d/default.conf': nginx_config},

619

ex_restart_policy='always'

620

)

621

622

print(f"Created load balancer: {lb_container.name}")

623

return lb_container

624

625

# Usage

626

# Scale web service to 5 containers

627

scale_container_service(driver, 'web-app', 5)

628

629

# Create load balancer for web service containers

630

web_containers = [c for c in driver.list_containers() if 'web-app' in c.name]

631

if web_containers:

632

lb = create_container_load_balancer(driver, web_containers, 80)

633

```

634

635

### Multi-Provider Container Management

636

637

```python

638

from libcloud.container.types import Provider

639

from libcloud.container.providers import get_driver

640

641

# Configure multiple container providers

642

container_providers = {

643

'docker_local': {

644

'driver': get_driver(Provider.DOCKER),

645

'config': {'host': 'unix:///var/run/docker.sock'}

646

},

647

'kubernetes': {

648

'driver': get_driver(Provider.KUBERNETES),

649

'config': {

650

'host': 'https://k8s-cluster:6443',

651

'key': 'api_token'

652

}

653

},

654

'ecs': {

655

'driver': get_driver(Provider.ECS),

656

'config': {

657

'key': 'aws_access_key',

658

'secret': 'aws_secret_key',

659

'region': 'us-east-1'

660

}

661

}

662

}

663

664

# Initialize drivers

665

container_drivers = {}

666

for name, config in container_providers.items():

667

cls = config['driver']

668

if name == 'docker_local':

669

container_drivers[name] = cls(**config['config'])

670

elif name == 'kubernetes':

671

container_drivers[name] = cls(**config['config'])

672

elif name == 'ecs':

673

container_drivers[name] = cls(

674

config['config']['key'],

675

config['config']['secret'],

676

region=config['config']['region']

677

)

678

679

# Deploy the same application across providers

680

def deploy_across_providers(app_config):

681

"""Deploy application across multiple container providers"""

682

deployments = {}

683

684

for provider_name, driver in container_drivers.items():

685

try:

686

print(f"Deploying to {provider_name}...")

687

688

container = driver.deploy_container(

689

name=f"{app_config['name']}-{provider_name}",

690

image=ContainerImage(

691

id=None,

692

name=app_config['image'],

693

tag=app_config['tag'],

694

driver=driver

695

),

696

ports=app_config['ports'],

697

environment=app_config['environment']

698

)

699

700

deployments[provider_name] = container

701

print(f"Deployed to {provider_name}: {container.name}")

702

703

except Exception as e:

704

print(f"Failed to deploy to {provider_name}: {e}")

705

706

return deployments

707

708

# Application configuration

709

app_config = {

710

'name': 'web-api',

711

'image': 'nginx',

712

'tag': 'alpine',

713

'ports': [80],

714

'environment': {'ENV': 'production'}

715

}

716

717

# Deploy across all providers

718

multi_deployments = deploy_across_providers(app_config)

719

```

720

721

## Exception Handling

722

723

```python

724

from libcloud.container.types import ContainerError

725

from libcloud.common.types import LibcloudError, InvalidCredsError

726

727

try:

728

# Deploy container

729

container = driver.deploy_container(

730

name='test-container',

731

image=ContainerImage(id=None, name='nginx', tag='latest', driver=driver)

732

)

733

except InvalidCredsError:

734

print("Invalid credentials for container provider")

735

except ContainerError as e:

736

print(f"Container specific error: {e}")

737

except LibcloudError as e:

738

print(f"General Libcloud error: {e}")

739

740

# Check container state before operations

741

container = driver.get_container('container-123')

742

if container.state == ContainerState.RUNNING:

743

success = container.stop()

744

elif container.state == ContainerState.STOPPED:

745

success = container.start()

746

```

747

748

## Provider-Specific Features

749

750

Different providers offer additional features through the `ex_*` parameter pattern:

751

752

```python

753

# Docker specific features

754

docker_driver = get_driver(Provider.DOCKER)('unix:///var/run/docker.sock')

755

756

# Deploy with Docker-specific options

757

container = docker_driver.deploy_container(

758

name='advanced-container',

759

image=ContainerImage(id=None, name='nginx', tag='latest', driver=docker_driver),

760

ex_privileged=True, # Run in privileged mode

761

ex_network_mode='host', # Use host networking

762

ex_restart_policy='always', # Always restart

763

ex_cpu_shares=512, # CPU priority

764

ex_memory_limit='1g' # Memory limit

765

)

766

767

# Kubernetes specific features

768

k8s_driver = get_driver(Provider.KUBERNETES)('https://k8s-api:6443', key='token')

769

770

# Deploy with Kubernetes-specific options

771

pod = k8s_driver.deploy_container(

772

name='k8s-app',

773

image=ContainerImage(id=None, name='nginx', tag='1.21', driver=k8s_driver),

774

ex_namespace='production', # Kubernetes namespace

775

ex_replicas=3, # Number of replicas

776

ex_service_type='LoadBalancer', # Service type

777

ex_resource_requests={'cpu': '100m', 'memory': '128Mi'}, # Resource requests

778

ex_resource_limits={'cpu': '500m', 'memory': '512Mi'} # Resource limits

779

)

780

781

# ECS specific features

782

ecs_driver = get_driver(Provider.ECS)('access_key', 'secret_key', region='us-east-1')

783

784

# Deploy with ECS-specific options

785

task = ecs_driver.deploy_container(

786

name='ecs-task',

787

image=ContainerImage(id=None, name='nginx', tag='latest', driver=ecs_driver),

788

ex_task_definition_arn='arn:aws:ecs:us-east-1:123456789012:task-definition/my-task:1',

789

ex_launch_type='FARGATE', # Launch type

790

ex_network_configuration={ # Network configuration for Fargate

791

'awsvpcConfiguration': {

792

'subnets': ['subnet-12345'],

793

'securityGroups': ['sg-12345'],

794

'assignPublicIp': 'ENABLED'

795

}

796

}

797

)

798

```

799

800

Check provider-specific documentation for additional capabilities available through the `ex_*` parameters and methods.