• (2022版)一套教程搞定k8s安装到实战 | Ingress


    视频来源:B站《(2022版)最新、最全、最详细的KubernetesK8s)教程,从K8s安装到实战一套搞定》

    一边学习一边整理老师的课程内容及试验笔记,并与大家分享,侵权即删,谢谢支持!

    附上汇总贴:(2022版)一套教程搞定k8s安装到实战 | 汇总_COCOgsta的博客-CSDN博客


    Ingress概念

    通俗来讲,Ingress和之前提到的Service、Deployment,也是一个k8s的资源类型,Ingress用于实现用域名的方式访问k8s内部应用。

    Ingress安装

    首先安装heml管理工具:helm.sh/docs/intro/…

    1. 下载helm-v3.0.0-linux-amd64.tar.gz
    1. tar zxvf helm-v3.0.0-linux-amd64.tar.gz
    1. mv linux-amd64/helm /usr/local/bin/helm
    1. helm version检查版本信息
    1. [root@k8s-master-lb ~]# helm version
    2. version.BuildInfo{Version:"v3.0.0", GitCommit:"e29ce2a54e96cd02ccfce88bee4f58bb6e2a28b6", GitTreeState:"clean", GoVersion:"go1.13.4"}
    3. You have new mail in /var/spool/mail/root
    4. 复制代码

    使用helm安装ingress:kubernetes.github.io/ingress-ngi…

    1. 添加ingress的helm仓库
    1. helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
    2. 复制代码
    1. 下载ingress的helm包至本地
    1. helm pull ingress-nginx/ingress-nginx
    2. 复制代码
    1. 更改对应的配置
    1. mkdir temp
    2. mv ingress-nginx-3.6.0.tgz temp/ # 实际helm仓库下载的为4.2.1,但为与视频环境保持一致,单独下载3.6.0
    3. cd temp/
    4. tar xf ingress-nginx-3.6.0.tgz
    5. cd ingress-nginx
    6. vim values.yaml
    7. 复制代码
    1. 需要修改的位置

      1. Controller和admissionWebhook的镜像地址,需要将公网镜像同步至公司内网镜像仓库
      2. hostNetwork设置为true
      3. dnsPolicy设置为ClusterFirstWithHostNet
      4. NodeSelector添加ingress:"true"部署至指定节点
      5. 类型更改为kind:DaemonSet
    1. 部署ingress

    给需要部署ingress的节点上打标签

    1. kubectl label node k8s-master03 ingress=true
    2. kubectl create ns ingress-nginx
    3. helm install ingress-nginx -n ingress-nginx .
    4. 复制代码

    安装成功后可以看到如下提示:

    1. [root@k8s-master-lb ingress-nginx]# helm install ingress-nginx -n ingress-nginx .
    2. NAME: ingress-nginx
    3. LAST DEPLOYED: Sat Aug 20 12:59:50 2022
    4. NAMESPACE: ingress-nginx
    5. STATUS: deployed
    6. REVISION: 1
    7. TEST SUITE: None
    8. NOTES:
    9. The ingress-nginx controller has been installed.
    10. Get the application URL by running these commands:
    11. export POD_NAME=$(kubectl --namespace ingress-nginx get pods -o jsonpath="{.items[0].metadata.name}" -l "app=ingress-nginx,component=,release=ingress-nginx")
    12. kubectl --namespace ingress-nginx port-forward $POD_NAME 8080:80
    13. echo "Visit http://127.0.0.1:8080 to access your application."
    14. An example Ingress that makes use of the controller:
    15. apiVersion: networking.k8s.io/v1beta1
    16. kind: Ingress
    17. metadata:
    18. annotations:
    19. kubernetes.io/ingress.class: nginx
    20. name: example
    21. namespace: foo
    22. spec:
    23. rules:
    24. - host: www.example.com
    25. http:
    26. paths:
    27. - backend:
    28. serviceName: exampleService
    29. servicePort: 80
    30. path: /
    31. # This section is only required if TLS is to be enabled for the Ingress
    32. tls:
    33. - hosts:
    34. - www.example.com
    35. secretName: example-tls
    36. If TLS is enabled for the Ingress, a Secret containing the certificate and key must also be provided:
    37. apiVersion: v1
    38. kind: Secret
    39. metadata:
    40. name: example-tls
    41. namespace: foo
    42. data:
    43. tls.crt: <base64 encoded cert>
    44. tls.key: <base64 encoded key>
    45. type: kubernetes.io/tls
    46. [root@k8s-master-lb ingress-nginx]#
    47. 复制代码

    检查ingress运行状态

    1. [root@k8s-master-lb ingress-nginx]# kubectl get pods -n ingress-nginx
    2. NAME READY STATUS RESTARTS AGE
    3. ingress-nginx-controller-9gf7t 1/1 Running 0 106s
    4. [root@k8s-master-lb ingress-nginx]#
    5. 复制代码

    ingress.yaml(单域名映射)

    1. apiVersion: networking.k8s.io/v1beta1 # networking.k8s.io/v1 / extensions/v1beta1
    2. kind: Ingress
    3. metadata:
    4. annotations:
    5. kubernetes.io/ingress.class: "nginx"
    6. name: example
    7. spec:
    8. rules: # 一个Ingress可以配置多个rules
    9. - host: foo.bar.com # 域名配置,可以不写,匹配**.bar.com
    10. http:
    11. paths: # 相当于nginx的location配合,同一个host可以配置多个path / /abc
    12. - backend:
    13. serviceName: nginx-svc
    14. servicePort: 80
    15. path: /
    16. 复制代码

    ingress-mulDomain.yaml(多域名映射)

    1. apiVersion: networking.k8s.io/v1beta1 # networking.k8s.io/v1 / extensions/v1beta1
    2. kind: Ingress
    3. metadata:
    4. annotations:
    5. kubernetes.io/ingress.class: "nginx"
    6. name: example
    7. spec:
    8. rules: # 一个Ingress可以配置多个rules
    9. - host: foo.bar.com # 域名配置,可以不写,匹配**.bar.com
    10. http:
    11. paths: # 相当于nginx的location配合,同一个host可以配置多个path / /abc
    12. - backend:
    13. serviceName: nginx-svc
    14. servicePort: 80
    15. path: /
    16. - host: foo2.bar.com # 域名配置,可以不写,匹配**.bar.com
    17. http:
    18. paths: # 相当于nginx的location配合,同一个host可以配置多个path / /abc
    19. - backend:
    20. serviceName: nginx-svc-external
    21. servicePort: 80
    22. path: /
    23. 复制代码

  • 相关阅读:
    Kibana使用Timelion根据时间序列展示数据
    在字节跳动,一个更好的企业级SparkSQL Server这么做
    git(部分)
    LeetCode第1题:两数之和
    mysql5.6免安装版安装步骤
    Java冒泡排序
    1414;【17NOIP普及组】成绩(信奥一本通)
    用Excel绘制统计图
    双馈风力发电机-900V直流混合储能并网系统Simulink仿真
    vue文字溢出...显示el-tooltip展示
  • 原文地址:https://blog.csdn.net/guolianggsta/article/details/126439595