2021-03-27 17:09:31
                
                    
                        摘要:截止到目前生产环境上要使用到的基础应用基本已经搭建完成,但似乎还缺少一点什么,对!就是docker镜像的仓库,如果没有私仓,我们需要把镜像手动推送各个node节点,这样太不方便了。
我们使用harbor来搭建:
一、安装
1. 确定30002,30003,30004端口没有被占用
2. helm repo add harbor https://helm.goharbor.io
3. helm search repo  harbor
4. helm pull harbor/harbor --version=1.6.1
5. tar -xf harbor-1.6.1.tgz
6. 改values里面storageClass的值nfs-storage(有3个地方)
7. 改ingress 
   ingress:
       hosts:
         core: harbor.qhfinance.com
         notary: notary.qhfinance.com
8. 改harborAdminPassword: xxxxx #设置密码
9. helm install harbor -f harbor-values.yaml --namespace qjy-public harbor/harbor --version 1.6.1
10. 配置host,随便一个节点的ip地址  
   vim /etc/hosts
   172.16.0.3 harbor.qhfinance.com 
二、访问
访问地址http://harbor.qhfinance.com/,默认用户名/密码为:admin/xxxxx
默认harbor只有一个公共的library项目,该项目的权限和docker hub一样不需要认证就可以拉取镜像,我们把它改成私有,也可以重新创建一个私有项目。
三、配置证书
因为我们部署的Harbour是有自带凭证(CA),所以需要再Docker Client加入凭证,这样Docker Client才有办法存取到私有的注册表。
首先,在Kubernetes Master使用以下指令取得凭证
kubectl get secret/harbor-harbor-ingress -n qjy-cicd -o jsonpath=……
                        阅读全文
                    
                 
                
             
            
                
                2021-03-25 15:47:21
                
                    
                        摘要:1、下载Charts包
git clone https://github.com/apache/skywalking-kubernetes
cd skywalking-kubernetes/chart
helm repo add elastic https://helm.elastic.co
helm dep up skywalking
2、修改配置文件 skywalking/values-my-es.yaml
oap:
  image:
    tag: 8.4.0-es7      # Set the right tag according to the existing Elasticsearch version
  storageType: elasticsearch7
ui:
  image:
    tag: 8.4.0
  service:
    type: NodePort
    externalPort: 80
    internalPort: 8080
    nodePort: 30008
elasticsearch:
  enabled: false 
  config:               # For users of an existing elasticsearch cluster,takes effect when `elasticsearch.enabled` is false
    host: elasticsearch-client.qjy-efk.svc.cluster.local
    port:
      http: 9200
    user: elastic         # [optional]
    password: xxxxx     # [optional]
3、执行
kubectl create namespace qjy-apm
helm install skywalking skywalking --namespace qjy-apm -f ./skywalking/values-my-es.yaml
                        阅读全文
                    
                 
                
             
            
                
                2021-03-20 19:51:21
                
                    
                        摘要:我们使用prometheus-operator来搭建
1、查看可使用的版本
helm repo add stable http://mirror.azure.cn/kubernetes/charts/
helm repo update
helm repo list
helm search repo prometheus-operator --versions
2、拉去指定版本的配置
helm pull stable/prometheus-operator --version=9.3.2
tar -xf stable-prometheus-operator-9.3.2.tgz
3、修改配置
配置内容比较多,要修改的信息如下:
分节编辑
1. alertmanager
  enabled: true
  ingress:
    enabled: true
    hosts: 
      - alert.qhfinance.com
2. grafana
  enabled: true
  adminPassword: admin
  ingress:
    enabled: true
    hosts: 
      - grafana.qhfinance.com
3. prometheus
  enabled: true
  ingress:
    enabled: true
    hosts: 
      - pus.qhfinance.com
  additionalServiceMonitors:  #配置自己的监控服务
     - name: hc
      namespaceSelector:
        any: true
      selector:
        matchLabels:
          qjy: app-metrics  #凡是打上了qjy的标签都会监控
      endpoints:
        - path: /metrics
          port: http
    - name: 
      namespaceSelector:
        any: true
      selector:
        matchLabels:
          qjy: ……
                        阅读全文
                    
                 
                
             
            
                
                2021-03-15 15:14:54
                
                    
                        摘要:上一篇我们搭建了Elasticsearch和Kibana,本文重点介绍fluentd
1、查看可使用的版本
helm repo add stable http://mirror.azure.cn/kubernetes/charts/
helm repo update
helm repo list
      
helm search repo fluentd-elasticsearch --versions
2、拉去指定版本的配置
helm pull stable/fluentd-elasticsearch --version=2.0.7
tar -xf fluentd-elasticsearch-2.0.7.tgz
3、修改配置
注意:
containers.input.conf下:path /var/log/containers/qjy-*.log 中 qjy-表示只手机容器名称为qjy-开头的日志
elasticsearch的密码在output.conf标签下配置user和password
cat es-fluentd-values.yaml-EOF
image:
  repository: registry.cn-beijing.aliyuncs.com/k8s-mqm/fluentd-elasticsearch
## Specify an imagePullPolicy (Required)
## It's recommended to change this to 'Always' if the image tag is 'latest'
## ref: http://kubernetes.io/docs/user-guide/images/#updating-images
  tag: v2.1.0 #v2.3.2
  pullPolicy: IfNotPresent
## Configure resource requests and limits
## ref: http://kubernetes.io/docs/user-guide/compute-resources/
##
resources: {}
  # limits:
  #   cpu: 100m
  #   memory: 500Mi
  # requests:
  #……
                        阅读全文
                    
                 
                
             
            
                
                2021-03-14 15:04:51
                
                    
                        摘要:一、资源准备
ElasticSearch 安装有最低安装要求,如果执行 Helm 安装命令后 Pod 无法正常启动,请检查是否符合最低要求的配置。
1、资源要求
ElasticSearch节点
CPU最小要求
内存最小要求
Kubernetes master
核心数  2
内存  2Gi
Kubernetes data
核心数  1
内存  2Gi
Kubernetes client
核心数  1
内存  2Gi
2、ElasticSearch 集群环境
集群名称
类型
副本
存储
网络模式
描述
elasticsearch
Master
3
5Gi
ClusterIP
主节节点,用于控制 ES 集群
elasticsearch
Data
3
50Gi
ClusterIP
数据节点,用于存储 ES 数据
elasticsearch
Client
2
无
NodePort(30200)
负责处理用户请求,实现请求转发、负载均衡
es-master 搭建一个 elasticsearch 至少需要 3 个 Pod 以防止集群脑裂。
es-data 数据节点至少需要 2 个 Pod 。数据节点将保留数据、接收查询和索引请求。
es-client 做为协调 elasticsearch 集群。至少需要 2 个。用于集群连接,并充当 HTTP 代理。如果不使用 es-clinet 那么 es-data 充当协调,尽量避免在较大的集群上这样做。
3、Kibana 环境信息
应用名称
副本数目
存储大小
网络模式
描述
Kibana
1
无
NodePort(30601)
用于展示 ElasticSearch 数据的应用
二、提前下载镜像
提前将要部署的应用的镜像下载,避免安装时因为镜像下载过慢而导致安装失败。这里我们主要用到的两个镜像。考虑与fluentd兼容,建议使用7.6.0
docker pull elasticsearch:7.6.0
docker pull kibana:7.6.0
三、创建集群证书
ElasticSearch 7.x 版本默认安装了x-pack插件,并且部分功能免费,这里我们配置安全证书文件。
1、生成证书文件
# 运行容器生成证书
docker run --name ……
                        阅读全文
                    
                 
                
             
            
                
                2021-03-11 18:19:24
                
                    
                        摘要:和上文中rabbitMq的搭建过程类似
1、查看可使用的版本
helm repo add aliyuncs https://apphub.aliyuncs.com
helm repo update
helm repo list
helm search repo redis-ha --versions
2、拉去指定版本的配置
helm pull aliyuncs/redis-ha --version=4.3.3
tar -xf redis-ha-4.3.3.tgz
tree redis-ha
3、修改storageClass
注意:我们有3台node节点,如果只有2台node节点还需要将replicas值改成2(1主1从)
如果想设置密码,可以跟进说明设置
cat redis-cluster-values.yaml-EOF
## Configure resource requests and limits
## ref: http://kubernetes.io/docs/user-guide/compute-resources/
##
image:
  repository: redis
  tag: 5.0.6-alpine
  pullPolicy: IfNotPresent
## replicas number for each component
replicas: 3
## Kubernetes priorityClass name for the redis-ha-server pod
# priorityClassName: 
## Custom labels for the redis pod
labels: {}
## Pods Service Account
## ref: https://kubernetes.io/docs/tasks/configure-pod-container/configure-service-account/
serviceAccount:
  ## Specifies whether a ServiceAccount should be created
  ##
  create: true
  ## The name of the ServiceAccount to use.
  ## If n……
                        阅读全文
                    
                 
                
             
            
                
                2021-03-10 19:29:38
                
                    
                        摘要:1、查看可使用tabbitmq-ha的版本
helm repo add aliyuncs https://apphub.aliyuncs.com
helm repo update
helm repo list
helm search repo rabbitmq-ha --versions
2、拉去指定版本的配置
helm pull aliyuncs/rabbitmq-ha --version=1.33.0
tar -xf rabbitmq-ha-1.33.0.tgz
3、查看文件
tree rabbitmq-ha
# 参考
├── charts # 依赖文件
├── Chart.yaml # 这个chart的版本信息
├── templates #模板
│   ├── deployment.yaml
│   ├── _helpers.tpl # 自定义的模板或者函数
│   ├── ingress.yaml
│   ├── NOTES.txt #这个chart的信息
│   ├── serviceaccount.yaml
│   ├── service.yaml
│   └── tests
│       └── test-connection.yaml
└── values.yaml #配置全局变量或者一些参数
4、修改value文件中的StorageClass
负责value文件,重命名为rabbitmq-cluster-values.yaml,并修改如下:
## Data Persistency
persistentVolume:
  enabled: true
  ## If defined, storageClassName: storageClass
  ## If set to -, storageClassName: , which disables dynamic provisioning
  ## If undefined (the default) or set to null, no storageClassName spec is
  ##   set, choosing the default provisioner.  (gp2 on AWS, standard on
  ##   GKE, AWS  OpenStack)
……
                        阅读全文
                    
                 
                
             
            
                
                2021-03-09 20:23:03
                
                    
                        摘要:前提条件,先到腾讯云购买一块cfs
这里加上cfs的ip地址为:172.16.0.8
一、挂载cfs
1. 启动 NFS 客户端
yum install nfs-utils
2. 创建待挂载目标目录
mkdir -p /nfs/
3. 挂载文件系统
sudo mount -t nfs -o vers=4.0,noresvport 172.16.0.8:/ /nfs
4. 创建k8s文件夹用于存k8s的文件夹
cd ../nfs
mkdir k8s #这里加上我们把文件都存储在cfs文件系统下的k8s目录下
二、设置开机自动挂载
第一步挂载cfs虽然成功,但当服务器重启时,要重新执行挂载。因此我们要实现开机自动挂载,这里使用autofs来实现
yum install autofs -y
vim /etc/auto.master
/nfs /etc/auto.misc
vim /etc/auto.misc
k8s -rw,soft,intr 172.16.0.8:/k8s
systemctl enable autofs
三、配置授权
# 清理rbac授权
kubectl delete -f nfs-rbac.yaml -n kube-system 
# 编写yaml
cat nfs-rbac.yaml-EOF
---
kind: ServiceAccount
apiVersion: v1
metadata:
  name: nfs-client-provisioner
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: nfs-client-provisioner-runner
rules:
  - apiGroups: []
    resources: [persistentvolumes]
    verbs: [get, list, watch, create, delete]
  - apiGroups: []
    resources: [persistentvolumeclaims]
    verbs: [get, list, watch, update]
  - apiGroups: [storage.k8s.io]
 ……
                        阅读全文
                    
                 
                
             
            
                
                2021-03-04 13:49:27
                
                    
                        摘要:以下都在master节点执行
一、安装Ingress
编辑官方的mandatory.yaml文件,只是在最后加入LimitRange配置,其他保留原始设置
cat mandatory.yaml-EOF
apiVersion: v1
kind: Namespace
metadata:
  name: ingress-nginx
  labels:
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/part-of: ingress-nginx
---
kind: ConfigMap
apiVersion: v1
metadata:
  name: nginx-configuration
  namespace: ingress-nginx
  labels:
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/part-of: ingress-nginx
---
kind: ConfigMap
apiVersion: v1
metadata:
  name: tcp-services
  namespace: ingress-nginx
  labels:
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/part-of: ingress-nginx
---
kind: ConfigMap
apiVersion: v1
metadata:
  name: udp-services
  namespace: ingress-nginx
  labels:
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/part-of: ingress-nginx
---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: nginx-ingress-serviceaccount
  namespace: ingress-nginx
  labels:
    app.kubernetes.io/name: i……
                        阅读全文
                    
                 
                
             
            
                
                2021-03-03 18:03:35
                
                    
                        摘要:本文介绍k8s集成的搭建过程:
搭建环境:腾讯云centos8.2
服务器4台:
master: 172.16.0.2
node1: 172.16.0.3
node2: 172.16.0.4
node3: 172.16.0.5
1.配置服务器名称
分别在每台服务器上设置
hostnamectl --static set-hostname k8s-master
hostnamectl --static set-hostname k8s-node1
hostnamectl --static set-hostname k8s-node2
hostnamectl --static set-hostname k8s-node3
以下2-8步骤在所有服务器上运行
2.关闭防火墙
systemctl stop firewalld #防止端口不开发,k8s集群无法启动
systemctl disable firewalld
3.关闭selinux
sed -i 's/enforcing/disabled/' /etc/selinux/config
setenforce 0 
4.关闭swap
vim /etc/fstab  永久关闭 注释swap那一行(访问内存分区,k8s无法启动)
swapoff -a    临时关闭
free          可以通过这个命令查看swap是否关闭了
5.将桥接的IPV4流量传递到iptables 的链
cat  /etc/sysctl.d/k8s.conf  EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
#加载模块
modprobe br_netfilter
6.安装Docker及同步时间
wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo -O/etc/yum.repos.d/docker-ce.repo
# 我们安装docker-ce-3:19.03.13-3.el8版本,避免与k8s版本不兼容
yum install -y docker-ce-3:19.03.13-3.el8
systemctl sta……
                        阅读全文