Closed zking2000 closed 3 months ago
from flask import Flask, jsonify, request
import requests
import time
import random
app = Flask(__name__)
def call_service_2():
time.sleep(random.uniform(0.5, 1.5)) # Simulate network latency
response = requests.get('http://service2:5001/api/v1/process')
return response.json()
def call_service_3():
time.sleep(random.uniform(0.5, 1.5)) # Simulate network latency
response = requests.get('http://service3:5002/api/v1/compute')
return response.json()
@app.route('/api/v1/start', methods=['GET'])
def start_process():
service2_result = call_service_2()
service3_result = call_service_3()
final_result = {
"service1": "start_process",
"service2_result": service2_result,
"service3_result": service3_result
}
return jsonify(final_result)
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000)
from flask import Flask, jsonify, request
import requests
import time
import random
app = Flask(__name__)
def call_service_3():
time.sleep(random.uniform(0.5, 1.5)) # Simulate network latency
response = requests.get('http://service3:5002/api/v1/analyze')
return response.json()
@app.route('/api/v1/process', methods=['GET'])
def process_data():
service3_result = call_service_3()
result = {
"service2": "process_data",
"service3_result": service3_result
}
return jsonify(result)
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5001)
from flask import Flask, jsonify, request
import time
import random
app = Flask(__name__)
@app.route('/api/v1/compute', methods=['GET'])
def compute():
time.sleep(random.uniform(0.5, 1.5)) # Simulate processing time
return jsonify({"service3": "compute"})
@app.route('/api/v1/analyze', methods=['GET'])
def analyze():
time.sleep(random.uniform(0.5, 1.5)) # Simulate processing time
return jsonify({"service3": "analyze"})
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5002)
# Base image
FROM python:3.9-slim
# Set working directory
WORKDIR /app
# Copy all files to the container
COPY . /app
# Install dependencies
RUN pip install flask requests
# Expose the port
EXPOSE 5000
# Command to run the app
CMD ["python", "service1.py"]
curl http://localhost:5000/api/v1/start
RUN mkdir -p ~/.pip && \
echo "[global]" > ~/.pip/pip.conf && \
echo "index-url = https://pypi.tuna.tsinghua.edu.cn/simple" >> ~/.pip/pip.conf
apiVersion: apps/v1
kind: Deployment
metadata:
name: service1-deployment
labels:
app: service1
spec:
replicas: 3
selector:
matchLabels:
app: service1
template:
metadata:
labels:
app: service1
spec:
containers:
- name: service1
image: service1:latest # 替换为实际的镜像名称和标签
ports:
- containerPort: 5000
resources:
limits:
cpu: "500m"
memory: "512Mi"
requests:
cpu: "200m"
memory: "256Mi"
env:
- name: APPDYNAMICS_AGENT_ACCOUNT_ACCESS_KEY
valueFrom:
secretKeyRef:
name: appd-secret
key: account-access-key
- name: APPDYNAMICS_AGENT_ACCOUNT_NAME
value: "your_account_name" # 替换为您的AppD账户名
- name: APPDYNAMICS_CONTROLLER_HOST_NAME
value: "your_controller_hostname" # 替换为您的AppD控制器主机名
- name: APPDYNAMICS_CONTROLLER_PORT
value: "8090"
- name: APPDYNAMICS_CONTROLLER_SSL_ENABLED
value: "false"
- name: APPDYNAMICS_AGENT_APPLICATION_NAME
value: "YourApplicationName" # 替换为您的应用程序名称
- name: APPDYNAMICS_AGENT_TIER_NAME
value: "Service1"
- name: APPDYNAMICS_AGENT_NODE_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: appd-agent
image: appdynamics/java-agent:latest # 使用适当的AppD代理镜像
imagePullPolicy: Always
env:
- name: APPDYNAMICS_AGENT_ACCOUNT_ACCESS_KEY
valueFrom:
secretKeyRef:
name: appd-secret
key: account-access-key
- name: JAVA_OPTS
value: "-javaagent:/opt/appdynamics/javaagent.jar"
volumeMounts:
- mountPath: /opt/appdynamics
name: appd-agent-repo
volumes:
- name: appd-agent-repo
emptyDir: {}
---
apiVersion: v1
kind: Service
metadata:
name: service1-service
spec:
selector:
app: service1
ports:
- protocol: TCP
port: 80
targetPort: 5000
type: ClusterIP
FE
PRODUCTION SERVICES
ORDER SERVICES
K8S MANIFEST