kubernetes nginx-ingress 使用
1.下载 nginx-ingress kubernetes yaml配置文件wget https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/mandatory.yaml2.修改deployment为demonset,删除replicas,并配置nodeselector.3.启动nginx-ingr...
1.下载 nginx-ingress kubernetes yaml配置文件
wget https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/mandatory.yaml
2.修改deployment为demonset,删除replicas,并配置nodeselector.
3.启动nginx-ingres-controller
kubectl apply -f mandatory-daemonset.yaml
查看运行是否正常,镜像比较大,500多M下载时间比较长
[root@centos75 nginx-ingress]# kubectl get pod -n ingress-nginx
NAME READY STATUS RESTARTS AGE
nginx-ingress-controller-mbg5v 1/1 Running 0 164m
nginx-ingress-controller-t5ck4 1/1 Running 0 164m
4.创建测试 pod
[root@centos75 myapp]# cat myapp.yaml
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: myapp
spec:
replicas: 2
template:
metadata:
labels:
app: myapp
spec:
# nodeSelector:
# zone: node2
containers:
- name: myapp
image: ikubernetes/myapp:v1
imagePullPolicy: IfNotPresent
—
###service
apiVersion: v1
kind: Service
metadata:
name: myapp
spec:
type: NodePort
selector:
app: myapp
ports:
- protocol: TCP
nodePort: 30036
port: 30036
targetPort: 80
kubectl apply -f myapp.yaml
5.为应用创建ingress
[root@centos75 myapp]# cat ingress-myapp.yaml
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: ingress-myapp
namespace: default
annotations:
kubernetes.io/ingress.class: “nginx”
spec:
rules:
- host: myapp.devops.com
http:
paths:
- path:
backend:
serviceName: myapp
servicePort: 80
[root@centos75 myapp]# kubectl apply -f ingress-myapp.yaml
ingress.extensions/ingress-myapp created
[root@centos75 myapp]# kubectl get ingress
NAME HOSTS ADDRESS PORTS AGE
ingress-myapp myapp.devops.com 80 7s
6.测试访问
开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!
更多推荐
所有评论(0)