切換到自己的目錄下如本文是放在/home/ubuntu下
cd /home/ubuntu
vim redis.conf
bind 0.0.0.0
protected-mode yes
port 6379
requirepass qwe123456
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize no
pidfile /var/run/redis_6379.pid
loglevel notice
logfile "/tmp/redis.log"
databases 16
always-show-logo no
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir /data
vim redis.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: redis-single-node
name: redis-single-node
spec:
progressDeadlineSeconds: 600 #部署進度截止時間
replicas: 1 #副本數
revisionHistoryLimit: 10 #修訂歷史記錄限制數
selector:
matchLabels:
app: redis-single-node #選擇器,用於選擇匹配的Pod
strategy:
rollingUpdate:
maxSurge: 1
maxUnavailable: 0
type: RollingUpdate
template:
metadata:
creationTimestamp: null
labels:
app: redis-single-node
spec:
containers:
- command:
- sh
- -c
- redis-server "/mnt/redis.conf"
env:
- name: TZ
value: Asia/Shanghai
- name: LANG
value: C.UTF-8
image: redis:5.0.4-alpine #Redis映象版本
imagePullPolicy: IfNotPresent
lifecycle: {}
livenessProbe:
failureThreshold: 2 #失敗的最大次數2次
initialDelaySeconds: 10 #啟動容器後10秒開始檢測
periodSeconds: 10 #每過10s檢測一次
successThreshold: 1 #只要成功了1次,就表示成功了。
tcpSocket:
port: 6379
timeoutSeconds: 2
name: redis-single-node
ports:
- containerPort: 6379
name: web
protocol: TCP
readinessProbe:
failureThreshold: 2
initialDelaySeconds: 10
periodSeconds: 10
successThreshold: 1
tcpSocket:
port: 6379
timeoutSeconds: 2
resources: #資源限制
limits: #最多可使用的資源
cpu: 100m #CPU的計量單位叫毫核(m)。一個節點的CPU核心數量乘以1000,得到的就是節點總的CPU總數量。如,一個節點有兩個核,那麼該節點的CPU總量為2000m
memory: 339Mi
requests: #代表容器啟動請求的資源限制,分配的資源必須要達到此要求
cpu: 10m
memory: 10Mi
securityContext: #上下文引數
privileged: false #特權,最高許可權
runAsNonRoot: false #禁止以root使用者啟動容器 true為禁止
terminationMessagePath: /dev/termination-log #表示容器的異常終止訊息的路徑,預設在 /dev/termination-log 下。當容器退出時,可以通過容器的狀態看到退出資訊。
terminationMessagePolicy: File #預設情況容器退出時,退出資訊會從檔案中讀取。 可以修改為 FallbackToLogsOnError 從紀錄檔中讀取
volumeMounts:
- mountPath: /usr/share/zoneinfo/Asia/Shanghai
name: tz-config
- mountPath: /etc/localtime
name: tz-config
- mountPath: /etc/timezone
name: timezone
- mountPath: /mnt
name: redis-conf
readOnly: true
dnsPolicy: ClusterFirst
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
terminationGracePeriodSeconds: 30 #在規定的terminationGracePeriodSeconds優雅時間內完成Pod優雅終止動作。預設是30秒
tolerations: #零容忍設定
- effect: NoExecute #即使在節點上存在汙點,也不會將Pod從該節點上刪除
key: node.kubernetes.io/unreachable
operator: Exists
tolerationSeconds: 30
- effect: NoExecute
key: node.kubernetes.io/not-ready
operator: Exists
tolerationSeconds: 30
volumes:
- hostPath:
path: /usr/share/zoneinfo/Asia/Shanghai
type: ""
name: tz-config
- hostPath:
path: /etc/timezone
type: ""
name: timezone
- configMap:
defaultMode: 420
name: redis-conf
name: redis-conf
kubectl create cm redis-conf --from-file=redis.conf
kubectl create -f redis.yaml
這裡使用Helm安裝所以需要先安裝一下Helm,如果已經安裝跳過2.1這個小步驟
wget https://get.helm.sh/helm-v3.12.1-linux-amd64.tar.gz
,如果遇到卡主那就是需要FQtar -zxvf helm-v3.12.1-linux-amd64.tar.gz
mv linux-amd64/helm /usr/local/bin/helm
helm repo add bitnami https://charts.bitnami.com/bitnami
,這邊如果要新增找其他倉庫地址可以去Artifact Hub搜尋相對於的倉庫地址。vim mongodb-pv.yaml
apiVersion: v1
kind: PersistentVolume
metadata:
name: mongodb-pv
spec:
capacity:
storage: 5Gi
accessModes:
- ReadWriteOnce
hostPath:
path: /bitnami/mongodb/data
以上內容中/bitnami/mongodb/data是主機真實路徑,小提示如果沒有許可權需要賦許可權給uid為1001
vim mongodb-pvc.yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: mongodb-pvc
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 5Gi
volumeName: mongodb-pv
vim mongodb-values.yaml
persistence:
enabled: true
existingClaim: "mongodb-pvc"
securityContext:
privileged: true
runAsUser: 1001
runAsGroup: 1001
fsGroup: 1001
auth:
rootPassword: "自定義密碼"
建立完以上三個檔案之後按順序執行如下:
①kubectl apply -f mongodb-pv.yaml
②kubectl apply -f mongodb-pvc.yaml
③helm install my-mongodb bitnami/mongodb -f mongodb-values.yaml --set volumePermissions.enabled=true
提示--set volumePermissions.enabled=true第③必須加這個不然pod建立的時候沒有許可權建立資料夾及檔案會報錯mkdir: cannot create directory '/bitnami/mongodb/data': Permission denied
安裝成功之後如果想讓外網存取跟上面redis一樣service編輯type為NodePort,設定nodePort: 27017,埠號自定義只要防火牆對外開放就行
解除安裝使用helm uninstall my-mongodb
mongodb://root:密碼@ip:埠
先切換至admin庫use admin
再執行修改 db.changeUserPassword("使用者名稱","密碼")
前置條件參考第2步安裝MongoDB中的建立pv跟pvc命名為kafka-pv和kafka-pvc
replicaCount: 1 # kafka 副本數
#global:
# storageClass: nfs-client # kafka 和 zookeeper 使用的儲存
heapOpts: "-Xmx1024m -Xms1024m" # kafka 啟動的 jvm 引數
persistence: # kafka 每個副本的儲存空間
enabled: true
existingClaim: "kafka-pvc"
resources:
limits:
cpu: 1000m
memory: 2Gi
requests:
cpu: 100m
memory: 100Mi
zookeeper:
replicaCount: 1 # zookeeper 的副本數
persistence:
enabled: true
existingClaim: "kafka-pvc"
resources:
limits:
cpu: 2000m
memory: 2Gi
externalAccess:
enabled: true # 開啟外部存取
autoDiscovery:
enabled: true
service:
type: NodePort # 開啟 nodeport
ports:
external: 9094
nodePorts: # nodeport 對應的埠,多少個 kafka 副本對應多少個埠
- 30001
# - 30002
# - 30003
執行部署helm install my-kafka bitnami/kafka -f kafka-values.yaml --set volumePermissions.enabled=true --set rbac.create=true
apiVersion: apps/v1
kind: Deployment
metadata:
name: kafka-console-ui
namespace: default
spec:
replicas: 1
selector:
matchLabels:
app: kafka-console-ui
template:
metadata:
labels:
app: kafka-console-ui
spec:
containers:
- name: kafka-console-ui
resources:
limits:
cpu: 1000m
memory: 1Gi
requests:
cpu: 10m
memory: 10Mi
image: wdkang/kafka-console-ui:latest
volumeMounts:
- mountPath: /etc/localtime
readOnly: true
name: time-data
volumes:
- name: time-data
hostPath:
path: /usr/share/zoneinfo/Asia/Shanghai
kind: Service
apiVersion: v1
metadata:
labels:
app: kafka-console-ui
name: kafka-console-ui
namespace: default
spec:
ports:
- port: 7766
targetPort: 7766
nodePort: 30088
selector:
app: kafka-console-ui
type: NodePort
①kubectl apply -f kafka-console-ui-service.yaml
②kubectl apply -f kafka-console-ui-deploy.yaml
kubectl rollout restart statefulset my-kafka -n default