在kubernetes(我使用的是minikube)中,我使用kubectl application-f nginx部署
部署了以下部署:
# nginx-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80
我得到部署. apps/nginx-部署创建
作为输出,当我运行kubectl获取部署
时,我得到:
NAME READY UP-TO-DATE AVAILABLE AGE
nginx-deployment 3/3 3 3 22s
我还使用kubectl application-f nginx-service. yml
命令部署了以下服务文件
apiVersion: v1
kind: Service
metadata:
name: nginx-service
spec:
type: NodePort
selector:
app: nginx
ports:
- name: "http"
port: 80
targetPort: 80
nodePort: 30080
输出是service/nginx-service创建
,kubectl get service
的输出是:
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 127d
nginx-service NodePort 10.99.253.196 <none> 80:30080/TCP 75s
但是,当我尝试通过在浏览器中输入10.99.253.196
来访问应用程序时,它不会加载,当我尝试localhost:30080它显示无法连接
。有人能帮助我理解为什么会发生这种情况/提供进一步的故障排除方向吗?
由于您使用的是minikube,因此您可能需要运行minikube服务nginx-service--url
,这将创建一条通往集群的隧道并公开服务。