部署ingress及使用

一、下载yaml文件
wget https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/mandatory.yaml
# 国内镜像
jicki/nginx-ingress-controller:0.21.0
# (国内)替换所有的 images

sed -i 's/quay\.io\/kubernetes-ingress-controller/jicki/g' *
二、导入yaml文件
kubectl  apply -f mandatory.yaml 

#查看
[root@k8s-m yaml]# kubectl  get pods -n ingress-nginx
NAME                                        READY   STATUS    RESTARTS   AGE
nginx-ingress-controller-766c77b7d4-nn4c7   1/1     Running   0          49s

三、# 创建一个基于service和Deployment

 [root@k8s-m yaml]# cat   ingress-deploy-demo.yaml
apiVersion: v1
kind: Service
metadata:
  name: nginx-svc
spec:
  selector: #标签选择
    name: nginx
  ports:
  - port: 80 #服务器端口
    name: http #名称
    targetPort: 80 #容器端口
    protocol: TCP #协议,默认TCP

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-nginx-deploy
spec:
  replicas: 3
  selector: 
    matchLabels:
      name: nginx
  template:
    metadata:
      labels:
        name: nginx 
    spec:
      containers: 
      - name: nginx
        image: nginx:alpine #镜像
        ports:
        - name: http
          containerPort: 80 #容器端口


#导入yaml文件
[root@k8s-m yaml]# kubectl apply -f   ingress-deploy-demo.yaml
service/nginx-svc unchanged
deployment.apps/my-nginx-deploy created

#查看
[root@k8s-m yaml]# kubectl  get pods
NAME                               READY   STATUS    RESTARTS   AGE
my-nginx-deploy-799879696c-7rlhl   1/1     Running   0          41s
my-nginx-deploy-799879696c-99v5g   1/1     Running   0          41s
my-nginx-deploy-799879696c-ljqjd   1/1     Running   0          41s
[root@k8s-m yaml]# kubectl  get svc 
NAME         TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)   AGE
kubernetes   ClusterIP   10.96.0.1      <none>        443/TCP   44m
nginx-svc    ClusterIP   10.96.182.50   <none>        80/TCP    3m43s

# 创建一个 基于 my-nginx-deploy的 ingress
[root@k8s-m yaml]# cat nginx-ingress.yaml 
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: ingress-nginx
spec:
  rules:
  - host: haha.zhang.com
    http:
      paths:
      - backend:
          serviceName: nginx-svc
          servicePort: 80

#查看
[root@k8s-m yaml]# kubectl  get ingress
NAME            HOSTS            ADDRESS   PORTS   AGE
ingress-nginx   haha.zhang.com             80      21s
#测试
[root@k8s-m yaml]# curl  haha.zhang.com -I
HTTP/1.1 200 OK
Server: nginx
Date: Thu, 20 Dec 2018 07:01:18 GMT
Content-Type: text/html
Connection: keep-alive
Keep-Alive: timeout=20
X-DIS-Request-ID: e21475c0d2fa20399819dbb15f21304a
P3P: CP="NON DSP COR ADMa OUR IND UNI COM NAV INT"
Cache-Control: no-cache

  

猜你喜欢

转载自www.cnblogs.com/zhangb8042/p/10149429.html
今日推荐