kubernetes中的测试服务

  |   0 评论   |   0 浏览

背景

kubernetes中有一些小巧的镜像,用来学习和调试环境。

kubernetes-bootcamp

安装

# kubectl run kubernetes-bootcamp --image=docker.io/jocatalin/kubernetes-bootcamp:v1 --port=8080

扩容

# kubectl scale deployments/kubernetes-bootcamp --replicas=4
deployment.extensions/kubernetes-bootcamp scaled

测试

# kubectl proxy
Starting to serve on 127.0.0.1:8001

# kubectl get pods
NAME                                   READY   STATUS    RESTARTS   AGE
kubernetes-bootcamp-7dc9765bf6-vbppq   1/1     Running   0          46m

# curl "localhost:8001/api/v1/namespaces/default/pods/kubernetes-bootcamp-7dc9765bf6-vbppq/proxy/"
Hello Kubernetes bootcamp! | Running on: kubernetes-bootcamp-7dc9765bf6-vbppq | v=1

NodeIP暴露服务

# kubectl expose deployment/kubernetes-bootcamp --type="NodePort" --port 8080

在容器中的交互式的shell中测试

$ kubectl exec -it kubernetes-bootcamp-5b48cfdcbd-5lbts bash

# curl "172.19.120.198:32373"
Hello Kubernetes bootcamp! | Running on: kubernetes-bootcamp-7dc9765bf6-tr8pc | v=1

ClusterIP暴露服务

# kubectl expose deployment/kubernetes-bootcamp --type="ClusterIP" --port 8080
service/kubernetes-bootcamp exposed

在容器中的交互式的shell中测试

$ kubectl exec -it kubernetes-bootcamp-5b48cfdcbd-5lbts bash

root@kubernetes-bootcamp-7dc9765bf6-pn2rs:/# curl "10.109.121.154:8080"
Hello Kubernetes bootcamp! | Running on: kubernetes-bootcamp-7dc9765bf6-pn2rs | v=1
root@kubernetes-bootcamp-7dc9765bf6-pn2rs:/# curl "10.109.121.154:8080"
Hello Kubernetes bootcamp! | Running on: kubernetes-bootcamp-7dc9765bf6-vbppq | v=1

source-ip-app

安装

kubectl run source-ip-app --image=gcr.azk8s.cn/google-containers/echoserver:1.4

扩容

# kubectl scale deployments/source-ip-app --replicas=4
deployment.extensions/source-ip-app scaled

测试

#  kubectl proxy
Starting to serve on 127.0.0.1:8001

# kubectl get pods
NAME                                   READY   STATUS    RESTARTS   AGE
source-ip-app-5697f896c4-ghwfs         1/1     Running   0          8m53s

# curl "localhost:8001/api/v1/namespaces/default/pods/source-ip-app-5697f896c4-ghwfs/proxy/"
Error: 'dial tcp 10.244.3.14:80: connect: connection refused'
Trying to reach: 'http://10.244.3.14/'

NodeIP暴露服务

# kubectl expose deployment/source-ip-app --type="NodePort" --port 8080
service/source-ip-app exposed

在容器中的交互式的shell中测试

$ kubectl exec -it kubernetes-bootcamp-5b48cfdcbd-5lbts bash

# curl -s "172.19.120.198:31994" | grep client
client_address=10.244.0.0

ClusterIP暴露服务

# kubectl expose deployment/source-ip-app --type="ClusterIP" --port 8080
service/source-ip-app exposed

在容器中的交互式的shell中测试

$ kubectl exec -it kubernetes-bootcamp-5b48cfdcbd-5lbts bash
root@kubernetes-bootcamp-7dc9765bf6-pn2rs:/# curl -s "10.98.188.59:8080" | grep client
client_address=10.244.3.13
root@kubernetes-bootcamp-7dc9765bf6-pn2rs:/# curl -s "10.98.188.59:8080" | grep client
client_address=10.244.3.13

参考