add new func

This commit is contained in:
pengtao 2022-03-28 17:13:04 +08:00
parent 1d4d05ee61
commit 05ef2c1e3c
10 changed files with 317 additions and 0 deletions

View File

@ -0,0 +1,8 @@
---
apiVersion: v1
kind: Namespace
metadata:
name: app02
labels:
name: app02
type: namespace

52
app02/app02_redis.yaml Normal file
View File

@ -0,0 +1,52 @@
---
apiVersion: v1
kind: Service
metadata:
name: redis-svc
namespace: app02
labels:
app: redis
spec:
type: NodePort
ports:
- port: 30080
targetPort: 6379
nodePort: 30001
selector:
app: app02-redis
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: app02-redis
namespace: app02
labels:
app: redis
spec:
replicas: 1
selector:
matchLabels:
app: redis
template:
metadata:
labels:
app: redis
name: redis-pod
spec:
containers:
- name: redis
image: redis
volumeMounts:
- name: redis-conf
mountPath: "/usr/local/etc"
command:
- "redis-server"
args:
- "/usr/local/etc/config/redis.conf"
volumes:
- name: redis-conf
configMap:
name: redis-conf
items:
- key: redis.conf
path: config/redis.conf

15
app02/busybox.yaml Normal file
View File

@ -0,0 +1,15 @@
apiVersion: v1
kind: Pod
metadata:
name: test01
namespace: app02
labels:
app: busybox
spec:
containers:
- name: test001
image: busybox
command:
- "ping"
args:
- "baidu.com"

50
app02/config/redis.conf Normal file
View File

@ -0,0 +1,50 @@
#daemonize yes
pidfile /data/redis.pid
port 6379
tcp-backlog 30000
timeout 0
tcp-keepalive 10
loglevel notice
logfile /data/redis.log
databases 16
#save 900 1
#save 300 10
#save 60 10000
stop-writes-on-bgsave-error no
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir /data
slave-serve-stale-data yes
slave-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
slave-priority 100
requirepass ibalife
maxclients 30000
appendonly no
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events KEA
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-entries 512
list-max-ziplist-value 64
set-max-intset-entries 1000
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10

59
app02/configmap.yaml Normal file
View File

@ -0,0 +1,59 @@
apiVersion: v1
data:
redis.conf: |-
#daemonize yes
protected-mode no
pidfile /data/redis.pid
bind 0.0.0.0
port 6379
tcp-backlog 30000
timeout 0
tcp-keepalive 10
loglevel notice
logfile /data/redis.log
databases 16
#save 900 1
#save 300 10
#save 60 10000
stop-writes-on-bgsave-error no
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir /data
slave-serve-stale-data yes
slave-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
slave-priority 100
#requirepass ibalife
maxclients 30000
appendonly no
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events KEA
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-entries 512
list-max-ziplist-value 64
set-max-intset-entries 1000
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
kind: ConfigMap
metadata:
name: redis-conf
namespace: app02

24
app02/ub_de.yaml Normal file
View File

@ -0,0 +1,24 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: ubuntu
namespace: app02
labels:
app: test02
spec:
replicas: 1
selector:
matchLabels:
app: test02
template:
metadata:
labels:
app: test02
name: ub-test
spec:
containers:
- name: test02
image: ubuntu
command:
- "/bin/bash"
args: ["-c", "while true; do echo hello; sleep 10;done"]

19
app02/ubuntu.yaml Normal file
View File

@ -0,0 +1,19 @@
apiVersion: v1
kind: Pod
metadata:
name: ubuntu
namespace: app02
labels:
app: ubuntu
spec:
containers:
- name: test002
image: ubuntu
command:
- "/bin/bash"
args: ["-c", "while true; do echo hello; sleep 10;done"]
# apt install iproute2 net-tools
# args:
# - "while true; do echo hello world; sleep 1;done"

28
app03/Dockerfile Normal file
View File

@ -0,0 +1,28 @@
#Download base image ubuntu 20.04
FROM ubuntu:latest
# LABEL about the custom image
LABEL maintainer="pengtao@kingsome.cn"
LABEL version="0.1"
LABEL description="This is custom Docker Image for \
the C++ Services."
# Disable Prompt During Packages Installation
ARG DEBIAN_FRONTEND=noninteractive
RUN apt update \
&& apt install -y python3 python3-pip \
&& python3 -m pip install fastapi uvicorn -i https://pypi.tuna.tsinghua.edu.cn/simple \
&& mkdir -p /app && chmod -R 755 /app \
&& rm -rf /var/lib/apt/lists/*
# Define the ENV variable
ENV APP_PORT=8000
EXPOSE $APP_PORT
# Copy start.sh script and define default command for the container
COPY . /app
WORKDIR /app
HEALTHCHECK CMD curl --fail http://localhost:$APP_PORT || exit 1
CMD ["/usr/bin/python3", "app.py"]

15
app03/app.py Normal file
View File

@ -0,0 +1,15 @@
# -*- coding: utf-8 -*-
from fastapi import FastAPI
app = FastAPI()
@app.get("/")
async def root():
return {"message": "Hello World"}
if __name__ == "__main__":
import uvicorn
uvicorn.run(app="app:app", host="0.0.0.0", port=8000, reload=True, debug=False)

47
readme.md Normal file
View File

@ -0,0 +1,47 @@
create namespace
kubectl apply -f namespace.yaml
# 查看 namespace
kubectl get namespace --show-labels
kubectl config view | grep namespace:
# 切换默认namespace
kubectl config current-context
kubectl config set-context test --namespace=app01 \
--cluster=docker-desktop \
--user=docker-desktop
kubectl config set-context prod --namespace=production \
--cluster=docker-desktop \
--user=docker-desktop
kubectl config view
# 切换环境到DEV
kubectl config use-context test
# check 当前环境
kubectl config current-context
# 查看配额
kubectl get resourcequotas
kubectl get resourcequota app01-redis --output=yaml
# create configmap
kubectl create configmap redis-conf --from-file=redis.conf
kubectl get configmap -n miles-app01
NAME DATA AGE
kube-root-ca.crt 1 3m30s
miles-app01-redis-conf 1 20s
# 创建和查看 pod
kubectl apply -f app01_redis.yaml
kubectl get pods -n app01
# 注意configMap 会挂在 /usr/local/etc/redis/redis.conf 上。与 mountPath 和 configMap 下的 path 一同指定
kubectl get pod miles-app01-redis-b48ff8c66-q5cv2 -n miles-app01
kubectl run busybox --image=busybox --command -- ping baidu.com
kubectl exec -it busybox -- /bin/bash
k describe replicaset.apps/app01-redis-64847ffc48
k get all -ALL
k describe pods