Mysql
https://www.cnblogs.com/zoulixiang/p/9910337.html
mkdir -p /opt/k8s/scriptcd /opt/k8s/scriptvi mysql-rc.yamlapiVersion: v1kind: ReplicationControllermetadata:name: mysql-rclabels:name: mysql-rcspec:replicas: 1selector:name: mysql-podtemplate:metadata:labels:name: mysql-podspec:containers:- name: mysqlimage: mysqlimagePullPolicy: IfNotPresentports:- containerPort: 3306env:- name: MYSQL_ROOT_PASSWORDvalue: "mysql"vi mysql-svc.yamlapiVersion: v1kind: Servicemetadata:name: mysql-svclabels:name: mysql-svcspec:type: NodePortports:- port: 3306protocol: TCPtargetPort: 3306name: httpnodePort: 31306selector:name: mysql-podkubectl create -f mysql-rc.yamlkubectl create -f mysql-svc.yamlkubectl get podskubectl get pod -o wide进入容器配置:docker ps -adocker exec -it xxxxx /bin/bash xxxx表示mysql的容器IDmysql -h127.0.0.1 -uroot -pmysqlalter user 'root'@'%' identified with mysql_native_password by'root';alter user 'root'@'%' identified by 'mysql';exit在使用 native 连接工具测试数据库链接。cd /optgit clone https://gitee.com/open_source/k8s_info.gitcd k8s_info/k8s-demomvn clean package -Dmaven.test.skip=true --update-snapshotsdocker build -t 192.168.216.3/k8s/k8s-demo:v1.0.0 .docker push 192.168.216.3/k8s/k8s-demo:v1.0.0kubectl 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/scriptcd /opt/k8s/scriptvi redis.conf#daemonize yesbind 0.0.0.0pidfile /data/redis.pidport 6379tcp-backlog 30000timeout 0tcp-keepalive 10loglevel noticelogfile /data/redis.logdatabases 16#save 900 1#save 300 10#save 60 10000stop-writes-on-bgsave-error nordbcompression yesrdbchecksum yesdbfilename dump.rdbdir /dataslave-serve-stale-data yesslave-read-only yesrepl-diskless-sync norepl-diskless-sync-delay 5repl-disable-tcp-nodelay noslave-priority 100requirepass ibalifemaxclients 30000appendonly noappendfilename "appendonly.aof"appendfsync everysecno-appendfsync-on-rewrite noauto-aof-rewrite-percentage 100auto-aof-rewrite-min-size 64mbaof-load-truncated yeslua-time-limit 5000slowlog-log-slower-than 10000slowlog-max-len 128latency-monitor-threshold 0notify-keyspace-events KEAhash-max-ziplist-entries 512hash-max-ziplist-value 64list-max-ziplist-entries 512list-max-ziplist-value 64set-max-intset-entries 1000zset-max-ziplist-entries 128zset-max-ziplist-value 64hll-sparse-max-bytes 3000activerehashing yesclient-output-buffer-limit normal 0 0 0client-output-buffer-limit slave 256mb 64mb 60client-output-buffer-limit pubsub 32mb 8mb 60hz 10创建 configMapkubectl create configmap redis-demo --from-file=redis.confvi redis-deploy.yamlapiVersion: apps/v1kind: Deploymentmetadata:name: redis-deployspec:replicas: 1selector:matchLabels:app: redis-deploytemplate:metadata:labels:app: redis-deployspec:containers:- name: redis-deployimage: redisvolumeMounts:- name: foomountPath: "/usr/local/etc"command:- "redis-server"args:- "/usr/local/etc/redis/redis.conf"volumes:- name: fooconfigMap:name: redis-demoitems:- key: redis.confpath: redis/redis.conf创建Deploymentkubectl apply -f redis-deploy.yaml --validate=falsevi redis-svc.yamlapiVersion: v1kind: Servicemetadata:name: redis-svclabels:name: redis-svcspec:type: NodePortports:- port: 6379targetPort: 6379name: redis-deploynodePort: 31379selector:app: redis-deploykubectl 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.yamlkubectl expose deployment java-demo --port=80 --target-port=8080 --type=NodePort -o yaml --dry-run > svc.yaml生成配置文件
K8S各模块缩写
NAME SHORTNAMES APIGROUP NAMESPACED KINDbindings true Bindingcomponentstatuses cs false ComponentStatusconfigmaps cm true ConfigMapendpoints ep true Endpointsevents ev true Eventlimitranges limits true LimitRangenamespaces ns false Namespacenodes no false Nodepersistentvolumeclaims pvc true PersistentVolumeClaimpersistentvolumes pv false PersistentVolumepods po true Podpodtemplates true PodTemplatereplicationcontrollers rc true ReplicationControllerresourcequotas quota true ResourceQuotasecrets true Secretserviceaccounts sa true ServiceAccountservices svc true Servicemutatingwebhookconfigurations admissionregistration.k8s.io false MutatingWebhookConfigurationvalidatingwebhookconfigurations admissionregistration.k8s.io false ValidatingWebhookConfigurationcustomresourcedefinitions crd,crds apiextensions.k8s.io false CustomResourceDefinitionapiservices apiregistration.k8s.io false APIServicecontrollerrevisions apps true ControllerRevisiondaemonsets ds apps true DaemonSetdeployments deploy apps true Deploymentreplicasets rs apps true ReplicaSetstatefulsets sts apps true StatefulSettokenreviews authentication.k8s.io false TokenReviewlocalsubjectaccessreviews authorization.k8s.io true LocalSubjectAccessReviewselfsubjectaccessreviews authorization.k8s.io false SelfSubjectAccessReviewselfsubjectrulesreviews authorization.k8s.io false SelfSubjectRulesReviewsubjectaccessreviews authorization.k8s.io false SubjectAccessReviewhorizontalpodautoscalers hpa autoscaling true HorizontalPodAutoscalercronjobs cj batch true CronJobjobs batch true Jobcertificatesigningrequests csr certificates.k8s.io false CertificateSigningRequestleases coordination.k8s.io true Leasebgpconfigurations crd.projectcalico.org false BGPConfigurationclusterinformations crd.projectcalico.org false ClusterInformationfelixconfigurations crd.projectcalico.org false FelixConfigurationglobalnetworkpolicies crd.projectcalico.org false GlobalNetworkPolicyglobalnetworksets crd.projectcalico.org false GlobalNetworkSethostendpoints crd.projectcalico.org false HostEndpointippools crd.projectcalico.org false IPPoolnetworkpolicies crd.projectcalico.org true NetworkPolicyevents ev events.k8s.io true Eventdaemonsets ds extensions true DaemonSetdeployments deploy extensions true Deploymentingresses ing extensions true Ingressnetworkpolicies netpol extensions true NetworkPolicypodsecuritypolicies psp extensions false PodSecurityPolicyreplicasets rs extensions true ReplicaSetnodes metrics.k8s.io false NodeMetricspods metrics.k8s.io true PodMetricsnetworkpolicies netpol networking.k8s.io true NetworkPolicypoddisruptionbudgets pdb policy true PodDisruptionBudgetpodsecuritypolicies psp policy false PodSecurityPolicyclusterrolebindings rbac.authorization.k8s.io false ClusterRoleBindingclusterroles rbac.authorization.k8s.io false ClusterRolerolebindings rbac.authorization.k8s.io true RoleBindingroles rbac.authorization.k8s.io true Rolepriorityclasses pc scheduling.k8s.io false PriorityClassstorageclasses sc storage.k8s.io false StorageClassvolumeattachments storage.k8s.io false VolumeAttachment
