Mysql

https://www.cnblogs.com/zoulixiang/p/9910337.html

  1. mkdir -p /opt/k8s/script
  2. cd /opt/k8s/script
  3. vi mysql-rc.yaml
  4. apiVersion: v1
  5. kind: ReplicationController
  6. metadata:
  7. name: mysql-rc
  8. labels:
  9. name: mysql-rc
  10. spec:
  11. replicas: 1
  12. selector:
  13. name: mysql-pod
  14. template:
  15. metadata:
  16. labels:
  17. name: mysql-pod
  18. spec:
  19. containers:
  20. - name: mysql
  21. image: mysql
  22. imagePullPolicy: IfNotPresent
  23. ports:
  24. - containerPort: 3306
  25. env:
  26. - name: MYSQL_ROOT_PASSWORD
  27. value: "mysql"
  28. vi mysql-svc.yaml
  29. apiVersion: v1
  30. kind: Service
  31. metadata:
  32. name: mysql-svc
  33. labels:
  34. name: mysql-svc
  35. spec:
  36. type: NodePort
  37. ports:
  38. - port: 3306
  39. protocol: TCP
  40. targetPort: 3306
  41. name: http
  42. nodePort: 31306
  43. selector:
  44. name: mysql-pod
  45. kubectl create -f mysql-rc.yaml
  46. kubectl create -f mysql-svc.yaml
  47. kubectl get pods
  48. kubectl get pod -o wide
  49. 进入容器配置:
  50. docker ps -a
  51. docker exec -it xxxxx /bin/bash xxxx表示mysql的容器ID
  52. mysql -h127.0.0.1 -uroot -pmysql
  53. alter user 'root'@'%' identified with mysql_native_password by'root';
  54. alter user 'root'@'%' identified by 'mysql';
  55. exit
  56. 在使用 native 连接工具测试数据库链接。
  57. cd /opt
  58. git clone https://gitee.com/open_source/k8s_info.git
  59. cd k8s_info/k8s-demo
  60. mvn clean package -Dmaven.test.skip=true --update-snapshots
  61. docker build -t 192.168.216.3/k8s/k8s-demo:v1.0.0 .
  62. docker push 192.168.216.3/k8s/k8s-demo:v1.0.0
  63. kubectl create -f java-deploy.yaml
  64. # 查看节点
  65. kubectl get pods
  66. # 查看日志
  67. kubectl logs k8s-demo-545c7679d-dvvt9
  68. # 创建服务
  69. kubectl create -f java-svc.yaml
  70. # 查看节点和端口映射
  71. kubectl get pods,svc

Redis

Deployment&Service方式

  1. mkdir -p /opt/k8s/script
  2. cd /opt/k8s/script
  3. vi redis.conf
  4. #daemonize yes
  5. bind 0.0.0.0
  6. pidfile /data/redis.pid
  7. port 6379
  8. tcp-backlog 30000
  9. timeout 0
  10. tcp-keepalive 10
  11. loglevel notice
  12. logfile /data/redis.log
  13. databases 16
  14. #save 900 1
  15. #save 300 10
  16. #save 60 10000
  17. stop-writes-on-bgsave-error no
  18. rdbcompression yes
  19. rdbchecksum yes
  20. dbfilename dump.rdb
  21. dir /data
  22. slave-serve-stale-data yes
  23. slave-read-only yes
  24. repl-diskless-sync no
  25. repl-diskless-sync-delay 5
  26. repl-disable-tcp-nodelay no
  27. slave-priority 100
  28. requirepass ibalife
  29. maxclients 30000
  30. appendonly no
  31. appendfilename "appendonly.aof"
  32. appendfsync everysec
  33. no-appendfsync-on-rewrite no
  34. auto-aof-rewrite-percentage 100
  35. auto-aof-rewrite-min-size 64mb
  36. aof-load-truncated yes
  37. lua-time-limit 5000
  38. slowlog-log-slower-than 10000
  39. slowlog-max-len 128
  40. latency-monitor-threshold 0
  41. notify-keyspace-events KEA
  42. hash-max-ziplist-entries 512
  43. hash-max-ziplist-value 64
  44. list-max-ziplist-entries 512
  45. list-max-ziplist-value 64
  46. set-max-intset-entries 1000
  47. zset-max-ziplist-entries 128
  48. zset-max-ziplist-value 64
  49. hll-sparse-max-bytes 3000
  50. activerehashing yes
  51. client-output-buffer-limit normal 0 0 0
  52. client-output-buffer-limit slave 256mb 64mb 60
  53. client-output-buffer-limit pubsub 32mb 8mb 60
  54. hz 10
  55. 创建 configMap
  56. kubectl create configmap redis-demo --from-file=redis.conf
  57. vi redis-deploy.yaml
  58. apiVersion: apps/v1
  59. kind: Deployment
  60. metadata:
  61. name: redis-deploy
  62. spec:
  63. replicas: 1
  64. selector:
  65. matchLabels:
  66. app: redis-deploy
  67. template:
  68. metadata:
  69. labels:
  70. app: redis-deploy
  71. spec:
  72. containers:
  73. - name: redis-deploy
  74. image: redis
  75. volumeMounts:
  76. - name: foo
  77. mountPath: "/usr/local/etc"
  78. command:
  79. - "redis-server"
  80. args:
  81. - "/usr/local/etc/redis/redis.conf"
  82. volumes:
  83. - name: foo
  84. configMap:
  85. name: redis-demo
  86. items:
  87. - key: redis.conf
  88. path: redis/redis.conf
  89. 创建Deployment
  90. kubectl apply -f redis-deploy.yaml --validate=false
  91. vi redis-svc.yaml
  92. apiVersion: v1
  93. kind: Service
  94. metadata:
  95. name: redis-svc
  96. labels:
  97. name: redis-svc
  98. spec:
  99. type: NodePort
  100. ports:
  101. - port: 6379
  102. targetPort: 6379
  103. name: redis-deploy
  104. nodePort: 31379
  105. selector:
  106. app: redis-deploy
  107. kubectl create -f redis-svc.yaml
  108. # 替换配置
  109. kubectl replace --force -f redis-svc.yaml

StatefulSet

kubectl

  1. kubectl create deployment java-demo --image=yueming33990/java-demo --dry-run -o yaml > deploy.yaml
  2. kubectl expose deployment java-demo --port=80 --target-port=8080 --type=NodePort -o yaml --dry-run > svc.yaml
  3. 生成配置文件

K8S各模块缩写

  1. NAME SHORTNAMES APIGROUP NAMESPACED KIND
  2. bindings true Binding
  3. componentstatuses cs false ComponentStatus
  4. configmaps cm true ConfigMap
  5. endpoints ep true Endpoints
  6. events ev true Event
  7. limitranges limits true LimitRange
  8. namespaces ns false Namespace
  9. nodes no false Node
  10. persistentvolumeclaims pvc true PersistentVolumeClaim
  11. persistentvolumes pv false PersistentVolume
  12. pods po true Pod
  13. podtemplates true PodTemplate
  14. replicationcontrollers rc true ReplicationController
  15. resourcequotas quota true ResourceQuota
  16. secrets true Secret
  17. serviceaccounts sa true ServiceAccount
  18. services svc true Service
  19. mutatingwebhookconfigurations admissionregistration.k8s.io false MutatingWebhookConfiguration
  20. validatingwebhookconfigurations admissionregistration.k8s.io false ValidatingWebhookConfiguration
  21. customresourcedefinitions crd,crds apiextensions.k8s.io false CustomResourceDefinition
  22. apiservices apiregistration.k8s.io false APIService
  23. controllerrevisions apps true ControllerRevision
  24. daemonsets ds apps true DaemonSet
  25. deployments deploy apps true Deployment
  26. replicasets rs apps true ReplicaSet
  27. statefulsets sts apps true StatefulSet
  28. tokenreviews authentication.k8s.io false TokenReview
  29. localsubjectaccessreviews authorization.k8s.io true LocalSubjectAccessReview
  30. selfsubjectaccessreviews authorization.k8s.io false SelfSubjectAccessReview
  31. selfsubjectrulesreviews authorization.k8s.io false SelfSubjectRulesReview
  32. subjectaccessreviews authorization.k8s.io false SubjectAccessReview
  33. horizontalpodautoscalers hpa autoscaling true HorizontalPodAutoscaler
  34. cronjobs cj batch true CronJob
  35. jobs batch true Job
  36. certificatesigningrequests csr certificates.k8s.io false CertificateSigningRequest
  37. leases coordination.k8s.io true Lease
  38. bgpconfigurations crd.projectcalico.org false BGPConfiguration
  39. clusterinformations crd.projectcalico.org false ClusterInformation
  40. felixconfigurations crd.projectcalico.org false FelixConfiguration
  41. globalnetworkpolicies crd.projectcalico.org false GlobalNetworkPolicy
  42. globalnetworksets crd.projectcalico.org false GlobalNetworkSet
  43. hostendpoints crd.projectcalico.org false HostEndpoint
  44. ippools crd.projectcalico.org false IPPool
  45. networkpolicies crd.projectcalico.org true NetworkPolicy
  46. events ev events.k8s.io true Event
  47. daemonsets ds extensions true DaemonSet
  48. deployments deploy extensions true Deployment
  49. ingresses ing extensions true Ingress
  50. networkpolicies netpol extensions true NetworkPolicy
  51. podsecuritypolicies psp extensions false PodSecurityPolicy
  52. replicasets rs extensions true ReplicaSet
  53. nodes metrics.k8s.io false NodeMetrics
  54. pods metrics.k8s.io true PodMetrics
  55. networkpolicies netpol networking.k8s.io true NetworkPolicy
  56. poddisruptionbudgets pdb policy true PodDisruptionBudget
  57. podsecuritypolicies psp policy false PodSecurityPolicy
  58. clusterrolebindings rbac.authorization.k8s.io false ClusterRoleBinding
  59. clusterroles rbac.authorization.k8s.io false ClusterRole
  60. rolebindings rbac.authorization.k8s.io true RoleBinding
  61. roles rbac.authorization.k8s.io true Role
  62. priorityclasses pc scheduling.k8s.io false PriorityClass
  63. storageclasses sc storage.k8s.io false StorageClass
  64. volumeattachments storage.k8s.io false VolumeAttachment