k8s学习三:创建一个nginx服务
【摘要】 部署nginx服务创建nginx服务:root@test02:/home/tioncico# kubectl create deployment nginx --image=nginx:1.14-alpinedeployment.apps/nginx createdroot@test02:/home/tioncico#复制查看nginx pod状态:root@test02:/home/ti...
部署nginx服务
创建nginx服务:
root@test02:/home/tioncico# kubectl create deployment nginx --image=nginx:1.14-alpine
deployment.apps/nginx created
root@test02:/home/tioncico#
复制
查看nginx pod状态:
root@test02:/home/tioncico# kubectl get pods
NAME READY STATUS RESTARTS AGE
nginx-7cbb8cd5d8-w9tn2 0/1 Pending 0 67s
root@test02:/home/tioncico#
复制
可以发现nginx属于pending状态,说明发生了异常
部署服务出错排查
查看pod详情:
root@test02:/home/tioncico# kubectl describe pod nginx
Name: nginx-7cbb8cd5d8-w9tn2
Namespace: default
Priority: 0
Node: <none>
Labels: app=nginx
pod-template-hash=7cbb8cd5d8
Annotations: <none>
Status: Pending
IP:
IPs: <none>
Controlled By: ReplicaSet/nginx-7cbb8cd5d8
Containers:
nginx:
Image: nginx:1.14-alpine
Port: <none>
Host Port: <none>
Environment: <none>
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-fzjmq (ro)
Conditions:
Type Status
PodScheduled False
Volumes:
kube-api-access-fzjmq:
Type: Projected (a volume that contains injected data from multiple sources)
TokenExpirationSeconds: 3607
ConfigMapName: kube-root-ca.crt
ConfigMapOptional: <nil>
DownwardAPI: true
QoS Class: BestEffort
Node-Selectors: <none>
Tolerations: node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Warning FailedScheduling 25s (x7 over 7m21s) default-scheduler 0/1 nodes are available: 1 node(s) had taint {node-role.kubernetes.io/master: }, that the pod didn't tolerate.
复制
可以看到最后的是 FailedScheduling , 原因是 0/1 nodes are available: 1 node(s) had taint {node-role.kubernetes.io/master: }, that the pod didn't tolerate.
这个是因为当创建单机版的 k8s 时,这个时候 master 节点是默认不允许调度 pod 。
解决方案是增加节点或者把master标记为可调度即可:
kubectl taint nodes --all node-role.kubernetes.io/master
复制
再次查看pod状态:
root@test02:/home/tioncico# kubectl get pods
NAME READY STATUS RESTARTS AGE
nginx-7cbb8cd5d8-w9tn2 1/1 Running 0 11m
root@test02:/home/tioncico#
复制
可看到已经可以运行
访问nginx
暴露nginx的端口:
kubectl expose deploy nginx --port=80 --target-port=80 --type=NodePort
复制
查看pod当前的ip地址:
root@test02:/home/tioncico# kubectl get pod,svc
NAME READY STATUS RESTARTS AGE
pod/nginx-7cbb8cd5d8-w9tn2 1/1 Running 0 15m
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 17h
service/nginx NodePort 10.96.119.144 <none> 80:32402/TCP 19s
root@test02:/home/tioncico#
复制
这个时候,通过curl 127.0.0.1:32402 即可访问nginx,
root@test02:/home/tioncico# curl http://127.0.0.1:32402
<!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>
复制

【声明】本内容来自华为云开发者社区博主,不代表华为云及华为云开发者社区的观点和立场。转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息,否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
作者其他文章
评论(0)