我是如何进行上云的2
python运行的dockerfile
FROM python:latest
MAINTAINER chinaskill
COPY web /root
COPY start.sh /root
RUN pip3 install flask requests \
&& chmod +x /root/start.sh
EXPOSE 80
CMD ["bash","/root/start.sh"]
start.sh
#!/bin/sh
python3 /root/web.py
~
python api网页端
from flask import Flask, jsonify
from flask import request
from huaweicloud import *
from urllib import parse
import json
app = Flask(__name__)
@app.route('/ecs', methods=['GET'])
def HaWei():
if request.args.get("id"):
id = request.args.get("id")
test = str(id_find(id), 'utf-8')
Server = json.loads(test)
elif request.args.get("name"):
name = request.args.get("name")
Server = str(name_find(name), 'utf-8')
Server = json.loads(Server)
return json.dumps(Server,indent=4)
if __name__ == "__main__":
app.run(host='0.0.0.0', port=80)
——————————————————————————————————————————
获取api端
from apig_sdk import signer
import requests
sig = signer.Signer()
# Set the AK/SK to sign and authenticate the request.
sig.Key = "EZLF2KRHSDSLTRDJTN0Q"
sig.Secret = "MjvUQObX3yG0MoIHERSeKhbJAbZezJrEqp32wmoO"
def id_find(id):
r = signer.HttpRequest("GET", "https://ecs.cn-east-3.myhuaweicloud.com/v1/0cb339febc80f3982fa9c00247628bb2/cloudservers/%s" %(id))
r.headers = {"X-Project-Id": "0cb339febc80f3982fa9c00247628bb2"}
sig.Sign(r)
resp = requests.request(r.method, r.scheme + "://" + r.host + r.uri, headers=r.headers, data=r.body)
return resp.content
def name_find(name):
r = signer.HttpRequest("GET", "https://ecs.cn-east-3.myhuaweicloud.com/v1/0cb339febc80f3982fa9c00247628bb2/cloudservers/detail?name=%s" %(name))
r.headers = {"X-Project-Id": "0cb339febc80f3982fa9c00247628bb2"}
sig.Sign(r)
resp = requests.request(r.method, r.scheme + "://" + r.host + r.uri, headers=r.headers, data=r.body)
return resp.content
k8s上云
创建deployment控制器
apiVersion: apps/v1
kind: Deployment
metadata:
name: web-api
namespace: default
labels:
k8s-app: web-api
spec:
replicas: 2
selector:
matchLabels:
k8s-app: web-api
template:
metadata:
labels:
k8s-app: web-api
spec:
containers:
- name: web-api
image: test:v1.8
创建svc控制器
kind: Service
apiVersion: v1
metadata:
labels:
k8s-app: web-api
name: web-network
namespace: default
spec:
type: NodePort
ports:
- port: 80
targetPort: 80
nodePort: 32222
selector:
k8s-app: web-api
- 点赞
- 收藏
- 关注作者
评论(0)