我是如何进行上云的2

举报
我是个大彩笔 发表于 2021/09/24 16:00:59 2021/09/24
【摘要】 python运行的dockerfileFROM python:latestMAINTAINER chinaskillCOPY web /rootCOPY start.sh /rootRUN pip3 install flask requests \&& chmod +x /root/start.shEXPOSE 80CMD ["bash","/root/start.sh"]start.sh#...

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

【版权声明】本文为华为云社区用户原创内容,未经允许不得转载,如需转载请自行联系原作者进行授权。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。