ingress控制器(3)
时间:2020-06-07 16:02 来源:潇湘夜雨 作者:华嵩阳 点击:次
/etc/nginx $ vi nginx.conf
## start server myapp.lzh.com
server {
server_name myapp.lzh.com ;
listen 80 ;
listen 443 ssl http2 ;
set $proxy_upstream_name "-";
ssl_certificate_by_lua_block {
certificate.call()
}
location / {
set $namespace "ingress-nginx";
set $ingress_name "ingress-web";
set $service_name "test-svc";
set $service_port "80";
set $location_path "/";
hosts:192.168.0.22 node2.k8s myapp.lzh.com
[root@master ingress]# curl myapp.lzh.com/hostname.html
mywebtest-ingress-7dd8d4c966-ggc88
[root@master ingress]# curl myapp.lzh.com/hostname.html
mywebtest-ingress-7dd8d4c966-xf9wm
[root@master ingress]# curl myapp.lzh.com/hostname.html
mywebtest-ingress-7dd8d4c966-ggc88
常见问题:pod一直无法创建
[root@master ~]# kubectl get pod -n ingress-nginx
NAME READY STATUS RESTARTS AGE
nginx-ingress-controller-7b6c66657d-grwj4 0/1 Pending 0 4h28m
[root@master ~]# kubectl describe pods nginx-ingress-controller-7b6c66657d-grwj4 -n ingress-nginx
Name: nginx-ingress-controller-7b6c66657d-grwj4
Namespace: ingress-nginx
Priority: 0
PriorityClassName: <none>
Node: <none>
Labels: app.kubernetes.io/name=ingress-nginx
app.kubernetes.io/part-of=ingress-nginx
pod-template-hash=7b6c66657d
Annotations: kubernetes.io/limit-ranger: LimitRanger plugin set: cpu, memory request for container nginx-ingress-controller
prometheus.io/port: 10254
prometheus.io/scrape: true
Status: Pending
IP:
Conditions:
Type Status
PodScheduled False
Volumes:
nginx-ingress-serviceaccount-token-phdwr:
Type: Secret (a volume populated by a Secret)
SecretName: nginx-ingress-serviceaccount-token-phdwr
Optional: false
QoS Class: Burstable
Node-Selectors: kubernetes.io/os=linux
Tolerations: node.kubernetes.io/not-ready:NoExecute for 300s
node.kubernetes.io/unreachable:NoExecute for 300s
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Warning FailedScheduling 64s (x4752 over 4h26m) default-scheduler 0/3 nodes are available: 3 node(s) didn't match node selector.
查看标签选择器:
nodeSelector:
kubernetes.io/os: linux
默认节点没这个标签:所以会调度失败
[root@master ~]# kubectl get node --show-labels
NAME STATUS ROLES AGE VERSION LABELS
master.k8s Ready master 570d v1.13.0 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/hostname=master.k8s,node-role.kubernetes.io/master=
node1.k8s Ready <none> 570d v1.13.0 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/hostname=node1.k8s
node2.k8s Ready <none> 570d v1.13.0 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/hostname=node2.k8s,memlelevel=lower
解决方法:为节点加标签
[root@master ~]# kubectl label nodes node2.k8s kubernetes.io/os=linux
node/node2.k8s labeled
[root@master ~]# kubectl get node --show-labels
NAME STATUS ROLES AGE VERSION LABELS
master.k8s Ready master 570d v1.13.0 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/hostname=master.k8s,node-role.kubernetes.io/master=
node1.k8s Ready <none> 570d v1.13.0 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/hostname=node1.k8s
node2.k8s Ready <none> 570d v1.13.0 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/hostname=node2.k8s,kubernetes.io/os=linux,memlelevel=lower
又出现新的问题:镜像拉取失败
[root@master ingress]# kubectl get pod -n ingress-nginx -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
nginx-ingress-controller-7b6c66657d-4cxq8 0/1 ErrImagePull 0 70s 10.244.2.57 node2.k8s <none> <none>
(责任编辑:liangzh) |