helm 3.0 最简单使用测试安装nginx-ingress

Posted Linux点滴运维实践

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了helm 3.0 最简单使用测试安装nginx-ingress相关的知识,希望对你有一定的参考价值。


1. 下载 helm 二进制安装包

[root@master01 ~]# wget https://get.helm.sh/helm-v3.1.2-linux-amd64.tar.gz .


2. 解压

[root@master01 ~]# tar -zxf helm-v3.1.2-linux-amd64.tar.gz


3. 把解压目录中的二进制文件,移到到二进制目录

[root@master01 ~]# mv linux-amd64/helm /usr/local/bin/helm


4. helm 版本信息

[root@master01 ~]# helm version
version.BuildInfo{Version:"v3.1.2", GitCommit:"d878d4d45863e42fd5cff6743294a11d28a9abce", GitTreeState:"clean", GoVersion:"go1.13.8"}
[root@master01 ~]#


5. 查看帮助 

[root@master01 ~]# helm help


6. 添加远程repo

[root@master01 ~]# helm repo add stable https://kubernetes-charts.storage.googleapis.com


7. 查找远程仓库的ingress nginx版本信息

[root@master01 ~]# helm search repo stable/nginx-ingress --version 1.34.3


8. 下载别人写好的Chart (有些官方的charts不适合我们,我们需要稍微修改下)

[root@master01 ~]# helm pull stable/nginx-ingress --version 1.34.3


9. 如果不需要修改,可以直接安装

[root@master01 ~]# helm install repo stable/nginx-ingress --version 1.34.3


10. 如果不直接安装,可以进入到刚才下载charts包并解析的目录,自行修改values.yaml

[root@master01 ingressnginx]# ls
nginx-ingress nginx-ingress-1.34.3.tgz
[root@master01 ingressnginx]# cd nginx-ingress
[root@master01 nginx-ingress]# ls
Chart.yaml ci OWNERS README.md templates values.yaml
[root@master01 nginx-ingress]# pwd
/root/ingressnginx/nginx-ingress
[root@master01 nginx-ingress]#


11. 这里我们修改并创建opsvirhost.yaml(values.yaml),使用hostNetwork: true,通过nodeSelector指定节点,自定义一个ingressClass

controller:
  replicaCount: 2
  hostNetwork: true
  ingressClass: opsvirhost
  nodeSelector:
    node-role.kubernetes.io/edge: 'opsvirhost'
  affinity:
    podAntiAffinity:
        requiredDuringSchedulingIgnoredDuringExecution:
        - labelSelector:
            matchExpressions:
            - key: app
              operator: In
              values:
              - nginx-ingress
            - key: component
              operator: In
              values:
              - controller
          topologyKey: kubernetes.io/hostname
  tolerations:
      - key: node-role.kubernetes.io/master
        operator: Exists
        effect: NoSchedule


defaultBackend:
  nodeSelector:
    node-role.kubernetes.io/edge: 'opsvirhost'
  tolerations:
      - key: node-role.kubernetes.io/master
        operator: Exists
        effect: NoSchedule


12. 生成virhost.yaml文件,也方便你修改查看;

[root@master01 nginx-ingress]# helm template --namespace=kube-tool -f ./opsvirhost.yaml . > ./virhost.yml
[root@master01 nginx-ingress]# sed -i 's/RELEASE-NAME/opsvirhost/g' virhost.yml


13. 为节点打标签

[root@master01 nginx-ingress]# kubectl label nodes master01 node-role.kubernetes.io/edge=opsvirhost
node/master01 labeled
[root@master01 nginx-ingress]# kubectl label nodes node01 node-role.kubernetes.io/edge=opsvirhost
node/node01 labeled
[root@master01 nginx-ingress]#


14. 创建Ingress Pod

[root@master01 nginx-ingress]# kubectl apply -f virhost.yml -n kube-tool
poddisruptionbudget.policy/opsvirhost-nginx-ingress-controller created
serviceaccount/opsvirhost-nginx-ingress created
serviceaccount/opsvirhost-nginx-ingress-backend created
clusterrole.rbac.authorization.k8s.io/opsvirhost-nginx-ingress created
clusterrolebinding.rbac.authorization.k8s.io/opsvirhost-nginx-ingress created
role.rbac.authorization.k8s.io/opsvirhost-nginx-ingress created
rolebinding.rbac.authorization.k8s.io/opsvirhost-nginx-ingress created
service/opsvirhost-nginx-ingress-controller created
service/opsvirhost-nginx-ingress-default-backend created
deployment.apps/opsvirhost-nginx-ingress-controller created
deployment.apps/opsvirhost-nginx-ingress-default-backend created
[root@master01 nginx-ingress]#


15. 验证安装

[root@master01 ~]# kubectl get pods -n kube-tool
NAME READY STATUS RESTARTS AGE
opsvirhost-nginx-ingress-controller-84598b88f6-h8hmj 1/1     Running 0          5m6s
opsvirhost-nginx-ingress-controller-84598b88f6-zp9md 1/1     Running 0          5m6s
opsvirhost-nginx-ingress-default-backend-559b74cf45-4tm6t 1/1     Running 0          5m6s
[root@master01 ~]# netstat -antp |grep -E "80|443" |grep nginx
tcp 0      0 0.0.0.0:443             0.0.0.0:*               LISTEN 2621/nginx: master
tcp 0      0 0.0.0.0:80              0.0.0.0:*               LISTEN 2621/nginx: master
tcp 0      0 10.96.0.1:35426         10.96.0.1:443           ESTABLISHED 2560/nginx-ingress-
[root@master01 ~]# 因为我们部署了2个副本,并且指定了node,所以可以查看下;
[root@node01 ~]# netstat -antp |grep -E "80|443" |grep nginx
tcp 0      0 0.0.0.0:443             0.0.0.0:*               LISTEN 26656/nginx: master
tcp 0      0 0.0.0.0:80              0.0.0.0:*               LISTEN 26656/nginx: master
tcp 0      0 10.96.0.1:51152         10.96.0.1:443           ESTABLISHED 26592/nginx-ingress
[root@node01 ~]#


16. 测试demo

[root@master01 ingressnginx]# cat demo.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: default-deployment-nginx
  namespace: default
spec:
  replicas: 1
  selector:
    matchLabels:
      run: default-deployment-nginx
  template:
    metadata:
      labels:
        run: default-deployment-nginx
    spec:
      containers:
      - name: default-deployment-nginx
        image: nginx:1.7.9
        ports:
        - containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
  name: default-svc-nginx
  namespace: default
spec:
  selector:
    run: default-deployment-nginx
  type: ClusterIP
  ports:
    - name: nginx-port
      port: 80
      targetPort: 80
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: default-ingress-nginx
  namespace: default
  annotations:
    kubernetes.io/ingress.class: "opsvirhost"
    nginx.ingress.kubernetes.io/proxy-body-size: 1000m
    nginx.ingress.kubernetes.io/rewrite-target: /
    nginx.ingress.kubernetes.io/use-regex: "true"
spec:
  rules:
  - host: test.k8s.vip
    http:
      paths:
      - path: /
        backend:
          serviceName: default-svc-nginx
          servicePort: nginx-port
[root@master01 ingressnginx]#


17.  添加hosts并访问

helm 3.0 最简单使用测试安装nginx-ingress

    https://hub.helm.sh/charts


您的关注是我写作的动力


往期分享




 


以上是关于helm 3.0 最简单使用测试安装nginx-ingress的主要内容,如果未能解决你的问题,请参考以下文章

安装helm服务以及搭建Helm测试环境

Helm安装使用

一键安装黑苹果系统3.0教程

纯搬运一键安装黑苹果系统3.0下载及使用教程

[容器] Helm的安装和使用

十六. k8s--helm安装与使用