更新时间:2023-02-22 18:12:44
让我们从头开始:***使用YAML配置文件对Kubernetes进行任何操作.如果出现问题,它将帮助您进行调试,并在以后重复您的操作.
Let's start from the beginning: it is always better to use YAML config files to do anything with Kubernetes. It will help you with debugging if something goes wrong and repeat your action in future.
首先,您使用以下命令创建广告连播:
First, you use the command to create the pod:
kubectl运行testproject --image acontainerregistry.azurecr.io/hellospring:v1
kubectl run testproject --image acontainerregistry.azurecr.io/hellospring:v1
YAML如下所示:
apiVersion: v1
kind: Pod
metadata:
name: test-app
spec:
containers:
- name: java-app
image: acontainerregistry.azurecr.io/hellospring:v1
ports:
- containerPort: 8090
,您可以将其作为命令应用
and you can apply it as a command:
kubectl apply -f ./pod.yaml
得到的结果与运行命令时得到的结果相同,但是除此之外,您还有将来可以使用的配置文件.
You get the same result as while running your command, but additionally you have the config file which can be used in future.
您正尝试使用以下命令公开您的广告连播:
You`re trying to expose your pod using command:
kubectl公开部署testproject --port = 5000 --type = LoadBalancer
kubectl expose deployments testproject --port=5000 --type=LoadBalancer
您的服务的YAML如下:
YAML for your service looks like:
apiVersion: v1
kind: Service
metadata:
name: java-service
labels:
name: test-app
spec:
type: LoadBalancer
ports:
- port: 5000
targetPort: 8090
name: http
selector:
name: test-app
做同样的事情但使用YAML可以描述更多内容,并确保您不会错过任何内容.
Doing the same but with using YAML allows to describe more and be sure you don't miss anything.
您试图卷曲localhost,但是我不确定您从该命令中期望得到什么:
You tried to curl the localhost but I`m not sure what did you expect from this command:
amhg $ curl > http:///127.0.0.1:8001/api/v1/proxy/namespaces/default/pods/testproject-bdf5b54d-gkk92/ 服务器内部错误
amhg$ curl http://127.0.0.1:8001/api/v1/proxy/namespaces/default/pods/testproject-bdf5b54d-gkk92/ Internal Server Error
创建服务后,请致电kubectl describe service $service_name
,您可以在此处找到它:
After you create the service, you call kubectl describe service $service_name
, which you can find here:
LoadBalancer Ingress: XX.XX.XX.XX
Port: http 5000/TCP
您可以卷曲该地址并从应用程序中收到答案.
You can curl this address and receive the answer from your application.
curl -v XX.XX.XX.XX:5000
不要忘记打开Azure防火墙上的端口.
Don't forget to open the port on Azure firewall.