• 欢迎访问VPS岛网站,国外VPS,国内VPS,国外服务器,国内服务器,服务器主机,测评及优惠码,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站 QQ群

Kubernetes(k8s)1.16.4部署 nginx-ingress 0.30

Nginx相关 李佳良 22次浏览 已收录 0个评论

下载Ingress-Nginx-0.30.0

https://github.com/kubernetes/ingress-nginx

docker pull registry.cn-beijing.aliyuncs.com/google_registry/nginx-ingress-controller:0.30.0
docker tag 89ccad40ce8e quay.io/kubernetes-ingress-controller/nginx-ingress-controller:0.30.0
docker rmi  registry.cn-beijing.aliyuncs.com/google_registry/nginx-ingress-controller:0.30.0

创建文件夹下载nginx-ingress包

mkdir ingress-nginx-0.30
cd ingress-nginx-0.30
wget https://github.com/kubernetes/ingress-nginx/archive/nginx-0.30.0.tar.gz
tar xf nginx-0.30.0.tar.gz
cp -a ingress-nginx-nginx-0.30.0/deploy/static/mandatory.yaml ./
vim mandatory.yaml 
修改ingress的yaml:
#191行
apiVersion: apps/v1
kind: DaemonSet   # 从Deployment改为DaemonSet
metadata:
  name: nginx-ingress-controller
  namespace: ingress-nginx
  labels:
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/part-of: ingress-nginx
spec:
  #replicas: 1   # 注释
#218行
      nodeSelector:
        kubernetes.io/hostname: k8s-master   # 修改处
      # 如下几行为新加行  作用【允许在master节点运行】
      tolerations:
      - key: node-role.kubernetes.io/master
        effect: NoSchedule
#251行
          ports:
            - name: http
              containerPort: 80
              hostPort: 80    # 添加处【可在宿主机通过该端口访问Pod】
              protocol: TCP
            - name: https
              containerPort: 443
              hostPort: 443   # 添加处【可在宿主机通过该端口访问Pod】
              protocol: TCP
kubectl apply -f mandatory.yaml
kubectl get pod -n ingress-nginx -o wide

创建第一个服务

vim deply_service1.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: myapp-deploy1
  namespace: default
spec:
  replicas: 3
  selector:
    matchLabels:
      app: myapp
      release: v1
  template:
    metadata:
      labels:
        app: myapp
        release: v1
        env: test
    spec:
      containers:
      - name: myapp
        image: registry.cn-beijing.aliyuncs.com/google_registry/myapp:v1
        imagePullPolicy: IfNotPresent
        ports:
        - name: http
          containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
  name: myapp-clusterip1
  namespace: default
spec:
  type: ClusterIP  # 默认类型
  selector:
    app: myapp
    release: v1
  ports:
  - name: http
    port: 80
    targetPort: 80
kubectl apply -f deply_service1.yaml 
kubectl get deploy -o wide
kubectl get rs -o wide
kubectl get pod -o wide --show-labels
kubectl get svc -o wide 

curl 10.244.2.***/hostname.html

创建第二个服务

vim deply_service2.yaml 
apiVersion: apps/v1
kind: Deployment
metadata:
  name: myapp-deploy2
  namespace: default
spec:
  replicas: 3
  selector:
    matchLabels:
      app: myapp
      release: v2
  template:
    metadata:
      labels:
        app: myapp
        release: v2
        env: test
    spec:
      containers:
      - name: myapp
        image: registry.cn-beijing.aliyuncs.com/google_registry/myapp:v2
        imagePullPolicy: IfNotPresent
        ports:
        - name: http
          containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
  name: myapp-clusterip2
  namespace: default
spec:
  type: ClusterIP  # 默认类型
  selector:
    app: myapp
    release: v2
  ports:
  - name: http
    port: 80
    targetPort: 80  
kubectl apply -f deply_service2.yaml 
kubectl get pod -o wide --show-labels -l "release=v2"
kubectl get svc -o wide

创建ingress外部访问yaml

vim ingress-http.yaml

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: nginx-http
  namespace: default
spec:
  rules:
    - host: test.demo1.com
      http:
        paths:
        - path: /
          backend:
            serviceName: myapp-clusterip1
            servicePort: 80
    - host: test.demo2.com
      http:
        paths:
        - path: /
          backend:
            serviceName: myapp-clusterip2
            servicePort: 80 
kubectl apply -f ingress-http.yaml 
kubectl get ingress -o wide

修改windos

C:\WINDOWS\System32\drivers\etc\hosts           
(k8s-master的ip)  test.demo1.com  test.demo2.com

浏览器访问test.demo1.com
浏览器访问test.demo2.com


VPS岛 的文章和资源来自互联网,仅作为参考资料,如果有侵犯版权的资源请尽快联系站长,我们会在24h内删除有争议的资源。丨 转载请注明Kubernetes(k8s)1.16.4部署 nginx-ingress 0.30
喜欢 (0)
发表我的评论
取消评论
表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址