Mysql
https://www.cnblogs.com/zoulixiang/p/9910337.html
mkdir -p /opt/k8s/script
cd /opt/k8s/script
vi mysql-rc.yaml
apiVersion: v1
kind: ReplicationController
metadata:
name: mysql-rc
labels:
name: mysql-rc
spec:
replicas: 1
selector:
name: mysql-pod
template:
metadata:
labels:
name: mysql-pod
spec:
containers:
- name: mysql
image: mysql
imagePullPolicy: IfNotPresent
ports:
- containerPort: 3306
env:
- name: MYSQL_ROOT_PASSWORD
value: "mysql"
vi mysql-svc.yaml
apiVersion: v1
kind: Service
metadata:
name: mysql-svc
labels:
name: mysql-svc
spec:
type: NodePort
ports:
- port: 3306
protocol: TCP
targetPort: 3306
name: http
nodePort: 31306
selector:
name: mysql-pod
kubectl create -f mysql-rc.yaml
kubectl create -f mysql-svc.yaml
kubectl get pods
kubectl get pod -o wide
进入容器配置:
docker ps -a
docker exec -it xxxxx /bin/bash xxxx表示mysql的容器ID
mysql -h127.0.0.1 -uroot -pmysql
alter user 'root'@'%' identified with mysql_native_password by'root';
alter user 'root'@'%' identified by 'mysql';
exit
在使用 native 连接工具测试数据库链接。
cd /opt
git clone https://gitee.com/open_source/k8s_info.git
cd k8s_info/k8s-demo
mvn clean package -Dmaven.test.skip=true --update-snapshots
docker build -t 192.168.216.3/k8s/k8s-demo:v1.0.0 .
docker push 192.168.216.3/k8s/k8s-demo:v1.0.0
kubectl create -f java-deploy.yaml
# 查看节点
kubectl get pods
# 查看日志
kubectl logs k8s-demo-545c7679d-dvvt9
# 创建服务
kubectl create -f java-svc.yaml
# 查看节点和端口映射
kubectl get pods,svc
Redis
Deployment&Service方式
mkdir -p /opt/k8s/script
cd /opt/k8s/script
vi redis.conf
#daemonize yes
bind 0.0.0.0
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
创建 configMap
kubectl create configmap redis-demo --from-file=redis.conf
vi redis-deploy.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: redis-deploy
spec:
replicas: 1
selector:
matchLabels:
app: redis-deploy
template:
metadata:
labels:
app: redis-deploy
spec:
containers:
- name: redis-deploy
image: redis
volumeMounts:
- name: foo
mountPath: "/usr/local/etc"
command:
- "redis-server"
args:
- "/usr/local/etc/redis/redis.conf"
volumes:
- name: foo
configMap:
name: redis-demo
items:
- key: redis.conf
path: redis/redis.conf
创建Deployment
kubectl apply -f redis-deploy.yaml --validate=false
vi redis-svc.yaml
apiVersion: v1
kind: Service
metadata:
name: redis-svc
labels:
name: redis-svc
spec:
type: NodePort
ports:
- port: 6379
targetPort: 6379
name: redis-deploy
nodePort: 31379
selector:
app: redis-deploy
kubectl create -f redis-svc.yaml
# 替换配置
kubectl replace --force -f redis-svc.yaml
StatefulSet
kubectl
kubectl create deployment java-demo --image=yueming33990/java-demo --dry-run -o yaml > deploy.yaml
kubectl expose deployment java-demo --port=80 --target-port=8080 --type=NodePort -o yaml --dry-run > svc.yaml
生成配置文件
K8S各模块缩写
NAME SHORTNAMES APIGROUP NAMESPACED KIND
bindings true Binding
componentstatuses cs false ComponentStatus
configmaps cm true ConfigMap
endpoints ep true Endpoints
events ev true Event
limitranges limits true LimitRange
namespaces ns false Namespace
nodes no false Node
persistentvolumeclaims pvc true PersistentVolumeClaim
persistentvolumes pv false PersistentVolume
pods po true Pod
podtemplates true PodTemplate
replicationcontrollers rc true ReplicationController
resourcequotas quota true ResourceQuota
secrets true Secret
serviceaccounts sa true ServiceAccount
services svc true Service
mutatingwebhookconfigurations admissionregistration.k8s.io false MutatingWebhookConfiguration
validatingwebhookconfigurations admissionregistration.k8s.io false ValidatingWebhookConfiguration
customresourcedefinitions crd,crds apiextensions.k8s.io false CustomResourceDefinition
apiservices apiregistration.k8s.io false APIService
controllerrevisions apps true ControllerRevision
daemonsets ds apps true DaemonSet
deployments deploy apps true Deployment
replicasets rs apps true ReplicaSet
statefulsets sts apps true StatefulSet
tokenreviews authentication.k8s.io false TokenReview
localsubjectaccessreviews authorization.k8s.io true LocalSubjectAccessReview
selfsubjectaccessreviews authorization.k8s.io false SelfSubjectAccessReview
selfsubjectrulesreviews authorization.k8s.io false SelfSubjectRulesReview
subjectaccessreviews authorization.k8s.io false SubjectAccessReview
horizontalpodautoscalers hpa autoscaling true HorizontalPodAutoscaler
cronjobs cj batch true CronJob
jobs batch true Job
certificatesigningrequests csr certificates.k8s.io false CertificateSigningRequest
leases coordination.k8s.io true Lease
bgpconfigurations crd.projectcalico.org false BGPConfiguration
clusterinformations crd.projectcalico.org false ClusterInformation
felixconfigurations crd.projectcalico.org false FelixConfiguration
globalnetworkpolicies crd.projectcalico.org false GlobalNetworkPolicy
globalnetworksets crd.projectcalico.org false GlobalNetworkSet
hostendpoints crd.projectcalico.org false HostEndpoint
ippools crd.projectcalico.org false IPPool
networkpolicies crd.projectcalico.org true NetworkPolicy
events ev events.k8s.io true Event
daemonsets ds extensions true DaemonSet
deployments deploy extensions true Deployment
ingresses ing extensions true Ingress
networkpolicies netpol extensions true NetworkPolicy
podsecuritypolicies psp extensions false PodSecurityPolicy
replicasets rs extensions true ReplicaSet
nodes metrics.k8s.io false NodeMetrics
pods metrics.k8s.io true PodMetrics
networkpolicies netpol networking.k8s.io true NetworkPolicy
poddisruptionbudgets pdb policy true PodDisruptionBudget
podsecuritypolicies psp policy false PodSecurityPolicy
clusterrolebindings rbac.authorization.k8s.io false ClusterRoleBinding
clusterroles rbac.authorization.k8s.io false ClusterRole
rolebindings rbac.authorization.k8s.io true RoleBinding
roles rbac.authorization.k8s.io true Role
priorityclasses pc scheduling.k8s.io false PriorityClass
storageclasses sc storage.k8s.io false StorageClass
volumeattachments storage.k8s.io false VolumeAttachment