k8s创建nginx-ingress-controller,以及创建ingress
部署ingress-nginx-controller#kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/static/mandatory.yaml#kubectl get pods -n ingress-nginxNAME...
部署ingress-nginx-controller
#kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/static/mandatory.yaml
#kubectl get pods -n ingress-nginx
NAME READY STATUS RESTARTS AGE
nginx-ingress-controller-568867bf56-xlrzv 1/1 Running 0 17h
部署service和deployment
#vim deploy-demo.yaml
#cat deploy-demo.yaml
apiVersion: v1
kind: Service
metadata:
name: myapp2
namespace: default
spec:
selector:
app: myapp2
release: canary
ports:
- name: http
port: 80
targetPort: 80
apiVersion: apps/v1
kind: Deployment
metadata:
name: myapp-deploy2
namespace: default
spec:
replicas: 3
selector:
matchLabels:
app: myapp2
release: canary
template:
metadata:
labels:
app: myapp2
release: canary
spec:
containers:
- name: myapp2
image: ikubernetes/myapp:v1
ports:
- name: http
containerPort: 80
#kubectl apply -f deploy-demo.yaml
#kubectl get pods
#kubectl get svc
#kubectl get pods -n ingress-nginx -w
#kubectl describe pods nginx-ingress-controller-76f97b74b-gr74q -n ingress-nginx
#kubectl get pods -n ingress-nginx -w
创建ingress
#cat ingress-myapp2.yaml
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: ingress-myapp2
namespace: default
annotations:
kubernetes.io/ingress.class: “nginx”
spec:
rules:
- host: myapp2.com
http:
paths:- path:
backend:
serviceName: myapp2
servicePort: 80
- path:
#kubectl apply -f ingress-myapp2.yaml
#kubectl get ingress
#kubectl describe ingress ingress-kube
#kubectl get pods -n ingress-nginx
#kubectl exec -n ingress-nginx -it nginx-ingress-controller-76f97b74b-#gr74q – /bin/sh
#cat nginx.conf
在访问的机器上hosts绑定,
然后在浏览器上访问myapp2.com
更多推荐
所有评论(0)