[yeqiang@localhost training]$ sh -x k8s/install_minicube.sh
+ set -x -e
+ curl -LO https://storage.googleapis.com/minikube/releases/v1.12.1/minikube-linux-amd64
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 55.7M 100 55.7M 0 0 496k 0 0:01:55 0:01:55 --:--:-- 522k
+ sudo install minikube-linux-amd64 /usr/local/bin/minikube
[sudo] password for yeqiang:
+ sudo dnf install kubernetes-client
Last metadata expiration check: 2:22:37 ago on Wed 12 Aug 2020 12:33:19 PM CST.
Package kubernetes-client-1.15.7-1.fc31.x86_64 is already installed.
Dependencies resolved.
Nothing to do.
Complete!
启动
[yeqiang@localhost training]$ sh k8s/start_minicube.sh
+ minikube start --driver=docker --image-mirror-country=cn --registry-mirror=https://r6w9c7qa.mirror.aliyuncs.com --image-repository=registry.cn-hangzhou.aliyuncs.com/google_containers --iso-url=https://kubernetes.oss-cn-hangzhou.aliyuncs.com/minikube/iso/minikube-v1.12.2.iso --base-image=registry.cn-hangzhou.aliyuncs.com/google_containers/kicbase:v0.0.10
😄 minikube v1.12.1 on Fedora 31
✨ Using the docker driver based on user configuration
✅ Using image repository registry.cn-hangzhou.aliyuncs.com/google_containers
👍 Starting control plane node minikube in cluster minikube
🔥 Creating docker container (CPUs=2, Memory=8000MB) ...
🎉 minikube 1.12.2 is available! Download it: https://github.com/kubernetes/minikube/releases/tag/v1.12.2
💡 To disable this notice, run: 'minikube config set WantUpdateNotification false'
🐳 Preparing Kubernetes v1.18.3 on Docker 19.03.2 ...
🔎 Verifying Kubernetes components...
🌟 Enabled addons: default-storageclass, storage-provisioner
🏄 Done! kubectl is now configured to use "minikube"
+ minikube addons enable ingress
🔎 Verifying ingress addon...
💣 enable failed: run callbacks: running callbacks: [verifying ingress addon pods : timed out waiting for the condition: timed out waiting for the condition]
😿 minikube is exiting due to an error. If the above message is not useful, open an issue:
👉 https://github.com/kubernetes/minikube/issues/new/choose
[yeqiang@localhost training]$ minikube addons enable ingress
🔎 Verifying ingress addon...
🌟 The 'ingress' addon is enabled
[yeqiang@localhost training]$ cd k8s/ && sh -x install_harbor.sh
+ set -x -e
+ kubectl create namespace harbor
namespace/harbor created
+ cd openssl-CA
+ kubectl create -n harbor secret tls hknaruto.com --cert=hknaruto.com.pem --key=hknaruto.com.key
secret/hknaruto.com created
+ cd harbor
+ helm install -n harbor harbor .
NAME: harbor
LAST DEPLOYED: Wed Aug 12 15:13:57 2020
NAMESPACE: harbor
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
Please wait for several minutes for Harbor deployment to complete.
Then you should be able to visit the Harbor portal at https://harbor.hknaruto.com
For more details, please visit https://github.com/goharbor/harbor
[yeqiang@localhost training]$ cd k8s/ && sh install_mysql.sh
+ cd mysql/
+ kubectl apply -f persistentVolume.yml
persistentvolume/mysql configured
persistentvolumeclaim/dev-volume-claim-mysql unchanged
+ kubectl apply -f deployment.yml
deployment.apps/k8s-dev-mysql configured
查看服务IP、端口
[yeqiang@localhost mysql]$ minikube ip
172.17.0.2
[yeqiang@localhost k8s]$ kubectl get service | grep mysql
mysql NodePort 10.111.28.196 <none> 3306:32048/TCP 6m25s
初始化
1。 启动minikube tunnel
[yeqiang@localhost mysql]$ minikube tunnel
[sudo] password for yeqiang:
Status:
machine: minikube
pid: 273957
route: 10.96.0.0/12 -> 172.17.0.2
minikube: Running
services: []
errors:
minikube: no errors
router: no errors
loadbalancer emulator: no errors
2。 倒入初始化脚本
部署training(kubernetes)
[yeqiang@harbor training]$ sh k8sDeploy.sh
[INFO] Scanning for projects...
[INFO]
[INFO] Using the MultiThreadedBuilder implementation with a thread count of 4
[INFO]
[INFO] --------------------------< com.example:demo >--------------------------
[INFO] Building demo 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:3.1.0:clean (default-clean) @ demo ---
[INFO] Deleting /home/yeqiang/code/training/target
[INFO]
[INFO] --- maven-resources-plugin:3.1.0:resources (default-resources) @ demo ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] Copying 2 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ demo ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 16 source files to /home/yeqiang/code/training/target/classes
[WARNING] /home/yeqiang/code/training/src/main/java/com/example/demo/util/CipherUtil.java:[12,16] sun.misc.HexDumpEncoder is internal proprietary API and may be removed in a future release
[WARNING] /home/yeqiang/code/training/src/main/java/com/example/demo/util/CipherUtil.java:[12,16] sun.misc.HexDumpEncoder is internal proprietary API and may be removed in a future release
[WARNING] /home/yeqiang/code/training/src/main/java/com/example/demo/util/CipherUtil.java:[12,16] sun.misc.HexDumpEncoder is internal proprietary API and may be removed in a future release
[WARNING] /home/yeqiang/code/training/src/main/java/com/example/demo/util/CipherUtil.java:[12,16] sun.misc.HexDumpEncoder is internal proprietary API and may be removed in a future release
[WARNING] /home/yeqiang/code/training/src/main/java/com/example/demo/util/CipherUtil.java:[12,16] sun.misc.HexDumpEncoder is internal proprietary API and may be removed in a future release
[WARNING] /home/yeqiang/code/training/src/main/java/com/example/demo/util/CipherUtil.java:[21,25] sun.misc.HexDumpEncoder is internal proprietary API and may be removed in a future release
[WARNING] /home/yeqiang/code/training/src/main/java/com/example/demo/util/CipherUtil.java:[21,61] sun.misc.HexDumpEncoder is internal proprietary API and may be removed in a future release
[INFO] /home/yeqiang/code/training/src/main/java/com/example/demo/util/JacksonUtil.java: /home/yeqiang/code/training/src/main/java/com/example/demo/util/JacksonUtil.java uses unchecked or unsafe operations.
[INFO] /home/yeqiang/code/training/src/main/java/com/example/demo/util/JacksonUtil.java: Recompile with -Xlint:unchecked for details.
[INFO]
[INFO] --- maven-resources-plugin:3.1.0:testResources (default-testResources) @ demo ---
[INFO] Not copying test resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ demo ---
[INFO] Not compiling test sources
[INFO]
[INFO] --- maven-surefire-plugin:2.22.2:test (default-test) @ demo ---
[INFO] Tests are skipped.
[INFO]
[INFO] --- maven-jar-plugin:3.1.2:jar (default-jar) @ demo ---
[INFO] Building jar: /home/yeqiang/code/training/target/demo-0.0.1-SNAPSHOT.jar
[INFO]
[INFO] --- spring-boot-maven-plugin:2.2.7.RELEASE:repackage (repackage) @ demo ---
[INFO] Replacing main artifact with repackaged archive
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.814 s (Wall Clock)
[INFO] Finished at: 2020-08-25T15:37:10+08:00
[INFO] ------------------------------------------------------------------------
Sending build context to Docker daemon 37.63MB
Step 1/6 : FROM openjdk:8-jdk-alpine
---> a3562aa0b991
Step 2/6 : VOLUME /tmp
---> Using cache
---> 66832f61c860
Step 3/6 : COPY BOOT-INF/lib /app/lib
---> Using cache
---> 5ec17ceeadab
Step 4/6 : COPY META-INF /app/META-INF
---> Using cache
---> ef3fda3d4b71
Step 5/6 : COPY BOOT-INF/classes /app
---> Using cache
---> e0a290b9e2a1
Step 6/6 : ENTRYPOINT tini -- java -XX:MaxRAMFraction=2 -cp app:app/lib/* com.example.demo.DemoApplication
---> Using cache
---> d31217544e4e
Successfully built d31217544e4e
Successfully tagged harbor.hknaruto.com/library/training:master.a216172
Username: admin
Password:
WARNING! Your password will be stored unencrypted in /home/yeqiang/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store
Login Succeeded
The push refers to repository [harbor.hknaruto.com/library/training]
3efd11b6f5f7: Pushed
d9e6d176174f: Pushed
73cad1bf8429: Pushed
ceaf9e1ebef5: Pushed
9b9b7f3d56a0: Pushed
f1b5933fe4b5: Pushed
master.a216172: digest: sha256:b40852cf2d1431e51e22a17d304786be4a8dd99312634eb8e98a428482a02fe2 size: 1576
service/training unchanged
deployment.apps/training configured
ingress.extensions/training-ingress unchanged
开发手册
异常
@ControllerAdvise + @ExceptionHandler注解在@RestController上,会导致原本应当返回500等http状态码,却返回了200,并且吞掉了原有的状态码
AtomicLong 分析 volatile 分析
。。。。。
运维手册
操作系统 Fedora 31
minikube
假定minikube是生产环境k8s集群,其中部署了mysql生产环境
安装
启动
查看minikube
kubenetes dashborad
启动
kubernetes单节点
nginx-ingress-controller
编辑/etc/ansible/manifests/ingress/nginx-ingress/nginx-ingress-hostport.yaml
采用hostNetwork模式,在宿主机器上开80 443端口
部署ingress
default-http-backend
故障排除
kubernetes-dashboard 故障,启动失败
排除方法:依次操作启动、停止firewalld
或者
ingress没有Endpoints
直接采用hostNetwork部署,后期前端应当采用keepalived+nginx作上层高可用代理,提供http、https,k8s集群ingress只需要提供http服务即可。
harbor(minikube、kubernetes)
安装
检查
注意:harbor所有pod处于Running状态需要等待一段时间
配置域名
获取ingress服务ip
手动配置本地/etc/hosts,增加记录
登陆到harbor
浏览器输入地址https://harbor.hknaruto.com/harbor/sign-in
登陆账号:admin
登陆密码:Harbor12345
docker信任自签名证书
增加”insecure-registries”: [“harbor.hknaruto.com”],
重启docker服务。
MySQL(minikube)未完成
k8s pet说明?
安装
查看服务IP、端口
初始化
1。 启动minikube tunnel
2。 倒入初始化脚本
部署training(kubernetes)
增加hosts配置
访问ingress暴露的服务