网站首页 文章专栏 02测试用例.md
创建配置文件
cat >tomcat_deploy.yaml<<EOF
apiVersion: apps/v1
kind: Deployment
metadata:
name: mytomcat
spec:
replicas: 1
selector:
matchLabels:
app: mytomcat
template:
metadata:
name: mytomcat
labels:
app: mytomcat
spec:
containers:
- name: mytomcat
image: tomcat:8
ports:
- containerPort: 8080
EOF
应用配置文件
kubectl apply -f tomcat_deploy.yaml
获取pod地址
kubectl get pods
通过pod地址访问
curl pod ip:pod port
创建deployment配置文件
cat >tensorflow_deploy.yaml<<EOF
apiVersion: apps/v1
kind: Deployment
metadata:
name: tensorflow
spec:
replicas: 1
selector:
matchLabels:
app: tensorflow
template:
metadata:
name: tensorflow
labels:
app: tensorflow
spec:
containers:
- name: tensorflow
imagePullPolicy: IfNotPresent
image: tensorflow1_18:v2
ports:
- containerPort: 6081
EOF
创建service配置文件
cat >tensorflow_service_nodeport.yaml<<EOF
apiVersion: v1
kind: Service
metadata:
name: front-tensorflow
labels:
app: tensorflow
spec:
ports:
- port: 6081
targetPort: 6081
nodePort: 30000
selector:
app: tensorflow
type: NodePort
EOF
应用配置文件
kubectl apply -f tensorflow_deploy.yaml
kubectl apply -f tensorflow_service_nodeport.yaml
使用浏览器访问应用,打开NodeIp:NodePort
页面
见第二章,《安装ingress》
先给node打标签
kubectl label nodes dsai slave=136
cat >tomcat_deploy_node.yaml<<EOF
apiVersion: apps/v1
kind: Deployment
metadata:
name: mytomcat
spec:
replicas: 1
selector:
matchLabels:
app: mytomcat
template:
metadata:
name: mytomcat
labels:
app: mytomcat
spec:
containers:
- name: mytomcat
image: tomcat:8
ports:
- containerPort: 8080
nodeSelector:
slave: "136"
EOF
应用配置文件
kubectl apply -f tomcat_deploy_node.yaml
cat >deepo_deploy_node.yaml<<EOF
apiVersion: apps/v1
kind: Deployment
metadata:
name: deepo
spec:
replicas: 1
selector:
matchLabels:
app: deepo
template:
metadata:
name: deepo
labels:
app: deepo
spec:
containers:
- name: deepo
imagePullPolicy: IfNotPresent
image: wenfengand/deepo:testd
resources:
limits:
nvidia.com/gpu: 1 # 必须为整数
nodeSelector:
slave: "136"
EOF
kubectl apply -f deepo_deploy_node.yaml
运行kubectl get pods
找到pod名称,与container进行交互
kubectl exec -it deepo-6ffccbdb4d-bwh99 /bin/bash
运行nvidia-smi
查看GPU数量
在gpu node节点查看所有GPU数量
可以看出在pods中gpu数量为1块,而slave节点中gpu数量为2块,k8s完成gpu调度。
cat >deepo_deploy_node_share.yaml<<EOF
apiVersion: apps/v1
kind: Deployment
metadata:
name: deepo
spec:
replicas: 1
selector:
matchLabels:
app: deepo
template:
metadata:
name: deepo
labels:
app: deepo
spec:
containers:
- name: deepo
imagePullPolicy: IfNotPresent
image: wenfengand/deepo:testd
nodeSelector:
slave: "136"
EOF
kubectl apply -f deepo_deploy_node_share.yaml
使用与隔离模式时相同的命令,可知容器内可见的GPU数量为2,与node中的GPU数量相同。