我的应用程序有问题。我的服务器上有 microk8s,我正在尝试部署应用程序。我编写了部署、入口和服务文件。deploy.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-nginx
spec:
replicas: 1
selector:
matchLabels:
run: my-nginx
template:
metadata:
labels:
run: my-nginx
spec:
containers:
- name: my-nginx
image: nginx
ports:
- containerPort: 80
入口文件
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: learn-linux.eu
annotations:
kubernetes.io/ingress.class: "nginx"
spec:
rules:
- host: learn-linux.eu
http:
paths:
- path: /
backend:
serviceName: nginx-service
servicePort: 80
服务.yaml
apiVersion: v1
kind: Service
metadata:
name: nginx-service
labels:
app: my-nginx
spec:
ports:
- port: 80
protocol: TCP
selector:
app: my-nginx
域记录 A 已更改为我拥有 microk8s 的服务器 IP。但是当我执行 curl learn-linux.eu 时,我得到:
curl:(7)无法连接到本地主机端口 80:连接被拒绝
但是当我对 pod IP 执行 curl 命令时,我收到 nginx 默认页面
root@learn-linux:~# curl 10.1.31.22
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
我的服务描述:
Name: nginx-service
Namespace: default
Labels: app=my-nginx
Annotations: <none>
Selector: app=my-nginx
Type: ClusterIP
IP: 10.152.183.44
Port: <unset> 80/TCP
TargetPort: 80/TCP
Endpoints: <none>
Session Affinity: None
Events: <none>
microk8s kubectl 描述部署 my-nginx
Name: my-nginx
Namespace: default
CreationTimestamp: Thu, 03 Sep 2020 12:18:15 +0200
Labels: <none>
Annotations: deployment.kubernetes.io/revision: 1
Selector: run=my-nginx
Replicas: 1 desired | 1 updated | 1 total | 1 available | 0 unavailable
StrategyType: RollingUpdate
MinReadySeconds: 0
RollingUpdateStrategy: 25% max unavailable, 25% max surge
Pod Template:
Labels: run=my-nginx
Containers:
my-nginx:
Image: nginx
Port: 80/TCP
Host Port: 0/TCP
Environment: <none>
Mounts: <none>
Volumes: <none>
Conditions:
Type Status Reason
---- ------ ------
Available True MinimumReplicasAvailable
Progressing True NewReplicaSetAvailable
OldReplicaSets: <none>
NewReplicaSet: my-nginx-5dc4865748 (1/1 replicas created)
Events: <none>
root@learn-linux:~# microk8s kubectl describe deployments my-nginx
Name: my-nginx
Namespace: default
CreationTimestamp: Thu, 03 Sep 2020 12:18:15 +0200
Labels: <none>
Annotations: deployment.kubernetes.io/revision: 1
Selector: run=my-nginx
Replicas: 1 desired | 1 updated | 1 total | 1 available | 0 unavailable
StrategyType: RollingUpdate
MinReadySeconds: 0
RollingUpdateStrategy: 25% max unavailable, 25% max surge
Pod Template:
Labels: run=my-nginx
Containers:
my-nginx:
Image: nginx
Port: 80/TCP
Host Port: 0/TCP
Environment: <none>
Mounts: <none>
Volumes: <none>
Conditions:
Type Status Reason
---- ------ ------
Available True MinimumReplicasAvailable
Progressing True NewReplicaSetAvailable
OldReplicaSets: <none>
NewReplicaSet: my-nginx-5dc4865748 (1/1 replicas created)
Events: <none>
microk8s kubectl 描述 pod my-nginx-5dc4865748
Name: my-nginx-5dc4865748-nbjww
Namespace: default
Priority: 0
Node: learn-linux/193.33.111.185
Start Time: Thu, 03 Sep 2020 12:18:16 +0200
Labels: pod-template-hash=5dc4865748
run=my-nginx
Annotations: <none>
Status: Running
IP: 10.1.31.22
IPs:
IP: 10.1.31.22
Controlled By: ReplicaSet/my-nginx-5dc4865748
Containers:
my-nginx:
Container ID: containerd://a15250412d4ce90ed9d5d31f98aff233cbe88bf26378429f6521e26a979281a2
Image: nginx
Image ID: docker.io/library/nginx@sha256:b0ad43f7ee5edbc0effbc14645ae7055e21bc1973aee5150745632a24a752661
Port: 80/TCP
Host Port: 0/TCP
State: Running
Started: Thu, 03 Sep 2020 12:18:32 +0200
Ready: True
Restart Count: 0
Environment: <none>
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from default-token-2wkwf (ro)
Conditions:
Type Status
Initialized True
Ready True
ContainersReady True
PodScheduled True
Volumes:
default-token-2wkwf:
Type: Secret (a volume populated by a Secret)
SecretName: default-token-2wkwf
Optional: false
QoS Class: BestEffort
Node-Selectors: <none>
Tolerations: node.kubernetes.io/not-ready:NoExecute for 300s
node.kubernetes.io/unreachable:NoExecute for 300s
Events: <none>
我不知道我做错了什么,我尝试了很多教程但仍然不起作用。有人知道吗?
#更新 microk8s kubectl 获取入口
NAME CLASS HOSTS ADDRESS PORTS AGE
learn-linux.eu <none> learn-linux.eu 80 15h
curl -v -H “主机:learn-linux.eu” 10.1.31.24
* Trying 10.1.31.24:80...
* TCP_NODELAY set
* Connected to 10.1.31.24 (10.1.31.24) port 80 (#0)
> GET / HTTP/1.1
> Host: learn-linux.eu
> User-Agent: curl/7.68.0
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Server: nginx/1.19.2
< Date: Fri, 04 Sep 2020 07:37:38 GMT
< Content-Type: text/html
< Content-Length: 612
< Last-Modified: Tue, 11 Aug 2020 14:50:35 GMT
< Connection: keep-alive
< ETag: "5f32b03b-264"
< Accept-Ranges: bytes
<
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>