kubenetes and Centos 7 常见脚本
安装 salt
yum install -y https://mirrors.aliyun.com/epel/7/ppc64/Packages/s/salt-ssh-2015.5.10-2.el7.noarch.rpm \
https://mirrors.aliyun.com/epel/7/ppc64/Packages/s/salt-2015.5.10-2.el7.noarch.rpm
然后将节点列表添加到 /etc/salt/roster
中
禁止询问是否信任
echo "StrictHostKeyChecking no" >> /etc/ssh/ssh_config
节点统一安装 nfs 驱动
yum install -y epel-release nfs-utils fuse s3fs-fuse
统一挂载 nfs
salt-ssh '*' cmd.run "mkdir /mnt/share; mount -t nfs 192.168.187.17:/export/share/ /mnt/share"
安装 helm
wget --no-check-certificate https://www.4wei.cn/files/helm-v3.9.2-linux-amd64.tar.gz
gunzip helm-v3.9.2-linux-amd64.tar.gz
tar -xf helm-v3.9.2-linux-amd64.tar
mv linux-amd64/helm /usr/local/bin/
chmod +x /usr/local/bin/helm
安装 Kuboard (内建用户)
使用 Docker 安装
docker run -d \
--restart=unless-stopped \
--name=kuboard \
-p 80:80/tcp \
-p 10081:10081/tcp \
-e KUBOARD_ENDPOINT="http://内网IP:80" \
-e KUBOARD_AGENT_SERVER_TCP_PORT="10081" \
-v /root/kuboard-data:/data \
eipwork/kuboard:v3
使用 k8s 安装
apiVersion: v1
kind: Namespace
metadata:
name: kuboard
---
apiVersion: apps/v1
kind: Deployment
metadata:
annotations: {}
labels:
k8s.kuboard.cn/layer: cloud
k8s.kuboard.cn/name: kuboard
name: kuboard
namespace: kuboard
spec:
replicas: 1
selector:
matchLabels:
k8s.kuboard.cn/layer: cloud
k8s.kuboard.cn/name: kuboard
template:
metadata:
labels:
k8s.kuboard.cn/layer: cloud
k8s.kuboard.cn/name: kuboard
spec:
containers:
- env:
- name: KUBOARD_ENDPOINT
value: 'http://{{改成你的节点IP}}:10080'
envFrom: []
image: 'swr.cn-east-2.myhuaweicloud.com/kuboard/kuboard:v3'
name: kuboard
ports:
- containerPort: 80
hostPort: 10080
name: kuboard
- containerPort: 10081
hostPort: 10081
name: tcp
resources:
limits:
cpu: '8'
memory: 32000Mi
requests:
cpu: '2'
memory: 4000Mi
volumeMounts:
- mountPath: /data
name: volume-hostpath
initContainers: []
nodeName: {{改成你的节点名称}}
volumes:
- hostPath:
path: /usr/share/kuboard
type: DirectoryOrCreate
name: volume-hostpath
安装 apisix
helm repo add apisix https://charts.apiseven.com
helm repo add bitnami https://charts.bitnami.com/bitnami
kubectl create ns ingress-apisix
helm install apisix apisix/apisix \
--set gateway.type=NodePort \
--set ingress-controller.enabled=true \
--namespace ingress-apisix \
--set ingress-controller.config.apisix.serviceNamespace=ingress-apisix
#可选参数
#--set persistence.storageClass=nfs
helm install apisix-dashboard apisix/apisix-dashboard --namespace ingress-apisix
kubectl create ns kubeapps
helm install kubeapps bitnami/kubeapps --namespace kubeapps
安装 spug
---
apiVersion: v1
kind: Namespace
metadata:
name: devops
---
apiVersion: apps/v1
kind: Deployment
metadata:
annotations: {}
labels:
k8s.kuboard.cn/layer: monitor
k8s.kuboard.cn/name: spug-mysql
name: spug-mysql
namespace: devops
resourceVersion: '8926315611'
spec:
progressDeadlineSeconds: 600
replicas: 1
revisionHistoryLimit: 10
selector:
matchLabels:
k8s.kuboard.cn/layer: cloud
k8s.kuboard.cn/name: spug-mysql
strategy:
rollingUpdate:
maxSurge: 25%
maxUnavailable: 25%
type: RollingUpdate
template:
metadata:
labels:
k8s.kuboard.cn/layer: cloud
k8s.kuboard.cn/name: spug-mysql
spec:
containers:
- args:
- '--port'
- '3306'
- '--character-set-server=utf8mb4'
- '--collation-server=utf8mb4_unicode_ci'
env:
- name: MYSQL_DATABASE
value: spug
- name: MYSQL_USER
value: spug
- name: MYSQL_PASSWORD
value: tikrnews
- name: MYSQL_ROOT_PASSWORD
value: tikrnews
image: 'mariadb:10.8.2'
imagePullPolicy: IfNotPresent
name: mysql
ports:
- containerPort: 3306
name: mysql
protocol: TCP
readinessProbe:
failureThreshold: 3
initialDelaySeconds: 20
periodSeconds: 30
successThreshold: 1
tcpSocket:
port: 3306
timeoutSeconds: 10
resources: {}
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
volumeMounts:
- mountPath: /var/lib/mysql
name: volume-cbs-mysql
dnsPolicy: ClusterFirst
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
terminationGracePeriodSeconds: 30
volumes:
- name: volume-cbs-mysql
persistentVolumeClaim:
claimName: spug-mysql
status: {}
---
apiVersion: v1
kind: Service
metadata:
annotations: {}
labels:
k8s.kuboard.cn/layer: monitor
k8s.kuboard.cn/name: spug-mysql
name: spug-mysql
namespace: devops
spec:
ports:
- name: mysql
port: 3306
protocol: TCP
targetPort: 3306
selector:
k8s.kuboard.cn/layer: cloud
k8s.kuboard.cn/name: spug-mysql
sessionAffinity: None
type: ClusterIP
status:
loadBalancer: {}
---
apiVersion: apps/v1
kind: Deployment
metadata:
annotations: {}
labels:
k8s.kuboard.cn/layer: monitor
k8s.kuboard.cn/name: spug
name: spug
namespace: devops
resourceVersion: '8926231419'
spec:
progressDeadlineSeconds: 600
replicas: 1
revisionHistoryLimit: 10
selector:
matchLabels:
k8s.kuboard.cn/layer: monitor
k8s.kuboard.cn/name: spug
strategy:
rollingUpdate:
maxSurge: 25%
maxUnavailable: 25%
type: RollingUpdate
template:
metadata:
labels:
k8s.kuboard.cn/layer: monitor
k8s.kuboard.cn/name: spug
spec:
containers:
- env:
- name: MYSQL_DATABASE
value: spug
- name: MYSQL_USER
value: spug
- name: MYSQL_PASSWORD
value: tikrnews
- name: MYSQL_HOST
value: spug-mysql
- name: MYSQL_PORT
value: '3306'
image: openspug/spug-service
imagePullPolicy: Always
name: spug
ports:
- containerPort: 80
name: spug
protocol: TCP
resources: {}
dnsPolicy: ClusterFirst
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
terminationGracePeriodSeconds: 30
status: {}
然后执行初始化
kubectl exec -n devops -it spug-645765565f-26zdk -- init_spug admin your-passwd