-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheks.py
More file actions
45 lines (39 loc) · 1.46 KB
/
eks.py
File metadata and controls
45 lines (39 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# create deployment and service
from kubernetes import client, config
# Load Kubernetes configuration
config.load_kube_config()
# Create a Kubernetes API client
api_client = client.ApiClient()
# Define the deployment
deployment = client.V1Deployment(
metadata=client.V1ObjectMeta(name="my-flask-app"),
spec=client.V1DeploymentSpec(
replicas=1,
selector=client.V1LabelSelector(match_labels={"app": "my-flask-app"}),
template=client.V1PodTemplateSpec(
metadata=client.V1ObjectMeta(labels={"app": "my-flask-app"}),
spec=client.V1PodSpec(
containers=[
client.V1Container(
name="my-flask-container",
image="568373317874.dkr.ecr.us-east-1.amazonaws.com/my_monitoring_app_image:latest",
ports=[client.V1ContainerPort(container_port=5000)],
)
]
),
),
),
)
# Create the deployment
api_instance = client.AppsV1Api(api_client)
api_instance.create_namespaced_deployment(namespace="default", body=deployment)
# Define the service
service = client.V1Service(
metadata=client.V1ObjectMeta(name="my-flask-service"),
spec=client.V1ServiceSpec(
selector={"app": "my-flask-app"}, ports=[client.V1ServicePort(port=5000)]
),
)
# Create the service
api_instance = client.CoreV1Api(api_client)
api_instance.create_namespaced_service(namespace="default", body=service)