![](/img/trans.png)
[英]How to expose the Kubernetes pod to the public internet using Azure container service
[英]Kubernetes: How to expose a Pod as a service
我正在学习 kubernetes 并使用以下命令创建了第一个 pod
kubectl run helloworld --image=<image-name> --port=8080
Pod 创建成功。 但由于它既不是 ReplicationController 也不是 Deloyment,我怎么能将它公开为服务。 请指教。
请参考文档kubernetes 服务理念https://kubernetes.io/docs/tutorials/kubernetes-basics/expose/expose-intro/页面末尾还有minikube的互动教程
您可以使用相同的选择器和标签集创建服务
apiVersion: v1
kind: Service
metadata:
name: my-service
spec:
selector:
app: helloworld
ports:
- protocol: TCP
port: 80
targetPort: 9376
因此,如果选择器匹配它会将流量路由到 POD 并且您可以公开它。
参考: https://kubernetes.io/docs/concepts/services-networking/service/
您可以在创建 pod 时简单地使用 --expose
$ kubectl run nginx --image=nginx --port=80 --expose
service/nginx created
pod/nginx created
感谢所有我能够使用以下命令实现(感谢 Amit kumar 的评论):
# Create a service for a pod valid-pod, which serves on port 444 with the name "frontend"
kubectl expose pod valid-pod --port=444 --name=frontend
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.