在原来Harbor 2.1.2安装 的基础上,继续集成Helm仓库
注意点:
helm3移除了tiller这个组件,默认通过~/.kube/config与集群进行交互,也就是说使用了与kubctl相同的上下文访问权限,若不在默认位置可通过–kubeconfig参数进行指定,按照官方安装文档安装即可直接使用
**-------------------------------Harbor服务器
相关操作如下----------------------------**
默认新版 harbor不会启用 chart repository service ,如果需要管理 helm ,我们需要在安装时添加额外的参数
## 默认安装$ cd /usr/local/harbor$ ./install.sh## 启动 chart repository service 服务$ cd /usr/local/harbor$ ./install.sh --with-chartmuseum等待安装完成,完成后会有如下提示:
[Step 0]: checking if docker is installed ...Note: docker version: 20.10.1[Step 1]: checking docker-compose is installed ...Note: docker-compose version: 1.27.4[Step 2]: loading Harbor images ...Loaded image: goharbor/chartmuseum-photon:v2.1.2Loaded image: goharbor/prepare:v2.1.2Loaded image: goharbor/harbor-log:v2.1.2Loaded image: goharbor/harbor-registryctl:v2.1.2Loaded image: goharbor/clair-adapter-photon:v2.1.2Loaded image: goharbor/harbor-db:v2.1.2Loaded image: goharbor/harbor-jobservice:v2.1.2Loaded image: goharbor/clair-photon:v2.1.2Loaded image: goharbor/notary-signer-photon:v2.1.2Loaded image: goharbor/harbor-portal:v2.1.2Loaded image: goharbor/redis-photon:v2.1.2Loaded image: goharbor/nginx-photon:v2.1.2Loaded image: goharbor/trivy-adapter-photon:v2.1.2Loaded image: goharbor/harbor-core:v2.1.2Loaded image: goharbor/registry-photon:v2.1.2Loaded image: goharbor/notary-server-photon:v2.1.2[Step 3]: preparing environment ...[Step 4]: preparing harbor configs ...prepare base dir is set to /usr/local/harborClearing the configuration file: /config/portal/nginx.confClearing the configuration file: /config/log/logrotate.confClearing the configuration file: /config/log/rsyslog_docker.confClearing the configuration file: /config/nginx/nginx.confClearing the configuration file: /config/core/envClearing the configuration file: /config/core/app.confClearing the configuration file: /config/registry/passwdClearing the configuration file: /config/registry/config.ymlClearing the configuration file: /config/registry/root.crtClearing the configuration file: /config/registryctl/envClearing the configuration file: /config/registryctl/config.ymlClearing the configuration file: /config/db/envClearing the configuration file: /config/jobservice/envClearing the configuration file: /config/jobservice/config.ymlGenerated configuration file: /config/portal/nginx.confGenerated configuration file: /config/log/logrotate.confGenerated configuration file: /config/log/rsyslog_docker.confGenerated configuration file: /config/nginx/nginx.confGenerated configuration file: /config/core/envGenerated configuration file: /config/core/app.confGenerated configuration file: /config/registry/config.ymlGenerated configuration file: /config/registryctl/envGenerated configuration file: /config/registryctl/config.ymlGenerated configuration file: /config/db/envGenerated configuration file: /config/jobservice/envGenerated configuration file: /config/jobservice/config.ymlloaded secret from file: /data/secret/keys/secretkeyGenerated configuration file: /config/chartserver/envGenerated configuration file: /compose_location/docker-compose.ymlClean up the input dirNote: stopping existing Harbor instance ...Stopping harbor-jobservice ... doneStopping nginx ... doneStopping harbor-core ... doneStopping harbor-portal ... doneStopping redis ... doneStopping registryctl ... doneStopping registry ... doneStopping harbor-db ... doneStopping harbor-log ... doneRemoving harbor-jobservice ... doneRemoving nginx ... doneRemoving harbor-core ... doneRemoving harbor-portal ... doneRemoving redis ... doneRemoving registryctl ... doneRemoving registry ... doneRemoving harbor-db ... doneRemoving harbor-log ... doneRemoving network harbor_harborRemoving network harbor_harbor-chartmuseumWARNING: Network harbor_harbor-chartmuseum not found.[Step 5]: starting Harbor ...Creating network "harbor_harbor" with the default driverCreating network "harbor_harbor-chartmuseum" with the default driverCreating harbor-log ... doneCreating harbor-db ... doneCreating registry ... doneCreating registryctl ... doneCreating redis ... doneCreating harbor-portal ... doneCreating chartmuseum ... doneCreating harbor-core ... doneCreating nginx ... doneCreating harbor-jobservice ... done✔ ----Harbor has been installed and started successfully.----这之后,就可以用上述 harbor 来管理 helm charts。
首先,需要在 harbor 上创建一个名为 helm-repo 的项目,如图所示:
**-------------------------------kmaster服务器
相关操作如下----------------------------**
$ wget https://get.helm.sh/helm-v3.4.2-linux-amd64.tar.gz$ tar -zxvf helm-v3.4.2-linux-amd64.tar.gz$ cd linux-amd64/# 拷贝helm到 /usr/local/bin $ cp helm /usr/local/bin$ helm The Kubernetes package managerCommon actions for Helm:- helm search: search for charts
- helm pull: download a chart to your local directory to view
- helm install: upload the chart to Kubernetes
- helm list: list releases of charts$ helm versionversion.BuildInfo{Version:"v3.4.2", GitCommit:"23dd3af5e19a02d4f4baa5b2f242645a1a3af629", GitTre eState:"clean", GoVersion:"go1.14.13"}$ vi /etc/hosts192.168.8.131 reg.local.comcat /etc/docker/daemon.json{"exec-opts":["native.cgroupdriver=systemd"],"log-driver":"json-file","log-opts":{"max-size":"100m"},"insecure-registries": ["reg.local.com"]}**-------------------------------harbor服务的认证信息
拷贝到kmaster服务器----------------------------**
[root@harbor cert]# lltotal 32-rw-r--r--. 1 root root 2033 Dec 31 04:25 ca.crt-rw-r--r--. 1 root root 3243 Dec 31 04:25 ca.key-rw-r--r--. 1 root root 17 Dec 31 04:25 ca.srl-rw-r--r--. 1 root root 2094 Dec 31 04:25 reg.local.com.cert-rw-r--r--. 1 root root 2094 Dec 31 04:25 reg.local.com.crt-rw-r--r--. 1 root root 1708 Dec 31 04:25 reg.local.com.csr-rw-r--r--. 1 root root 3247 Dec 31 04:25 reg.local.com.key-rw-r--r--. 1 root root 263 Dec 31 04:25 v3.ext[root@kmaster cert]# lltotal 32-rw-r--r-- 1 root root 2033 Dec 31 04:25 ca.crt-rw-r--r-- 1 root root 3243 Dec 31 04:25 ca.key-rw-r--r-- 1 root root 17 Dec 31 04:25 ca.srl-rw-r--r-- 1 root root 2094 Dec 31 04:25 reg.local.com.cert-rw-r--r-- 1 root root 2094 Dec 31 04:25 reg.local.com.crt-rw-r--r-- 1 root root 1708 Dec 31 04:25 reg.local.com.csr-rw-r--r-- 1 root root 3247 Dec 31 04:25 reg.local.com.key-rw-r--r-- 1 root root 263 Dec 31 04:25 v3.ext-------------------------------kmaster服务器相关操作如下----------------------------
$ helm repo add stable https://charts.helm.sh/stable$ helm repo add --ca-file /data/cert/ca.crt --cert-file /data/cert/reg.local.com.cert --key-file /data/cert/reg.local.com.key test https://reg.local.com/chartrepo/helm-repo"test" has been added to your repositories$ helm repo updateHang tight while we grab the latest from your chart repositories......Successfully got an update from the "test" chart repository...Successfully got an update from the "stable" chart repository$ helm install stable/mysql --generate-name$ helm lshelm3 现在默认不支持推送到charts库,需要安装插件helm-push
$ helm plugin install https://github.com/chartmuseum/helm-pushDownloading and installing helm-push v0.9.0 ...https://github.com/chartmuseum/helm-push/releases/download/v0.9.0/helm-push_0.9.0_linux_amd64.tar.gzInstalled plugin: push$ helm repo listNAME URLstable https://charts.helm.sh/stabletest https://reg.local.com/chartrepo/helm-repo$ helm create mychartCreating mychart$ lltotal 8drwxr-xr-x 2 root root 6 Jan 6 15:15 charts-rw-r--r-- 1 root root 1098 Jan 6 15:15 Chart.yamldrwxr-xr-x 3 root root 162 Jan 6 15:15 templates-rw-r--r-- 1 root root 1800 Jan 6 15:15 values.yaml$ helm lint ./mychart==> Linting ./mychartError unable to check Chart.yaml file in chart: stat mychart/Chart.yaml: no such file or directoryError: 1 chart(s) linted, 1 chart(s) failed[root@kmaster mychart]# cd ..[root@kmaster ~]# helm lint ./mychart==> Linting ./mychart[INFO] Chart.yaml: icon is recommended1 chart(s) linted, 0 chart(s) failed$ helm push mychart test --ca-file /data/cert/ca.crt -u admin -p Harbor12345Pushing mychart-0.1.0.tgz to test...Done.-------------------------------harbor服务器相关操作如下----------------------------
版本0.1.0
-------------------------------kmaster服务器相关操作如下----------------------------
$ helm listNAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION$ helm install my1 mychartNAME: my1LAST DEPLOYED: Wed Jan 6 15:57:47 2021NAMESPACE: defaultSTATUS: deployedREVISION: 1NOTES:1. Get the application URL by running these commands:
export POD_NAME=$(kubectl get pods --namespace default -l "app.kubernetes.io/name=mychart,app.kubernetes.io/instance=my1" -o jsonpath="{.items[0].metadata.name}")
export CONTAINER_PORT=$(kubectl get pod --namespace default $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}")
echo "Visit http://127.0.0.1:8080 to use your application"
kubectl --namespace default port-forward $POD_NAME 8080:$CONTAINER_PORT$ helm listNAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSIONmy1 default 1 2021-01-06 15:57:47.410255239 +0900 JST deployed mychart-0.1.0 1.16.0$ helm uninstall my1release "my1" uninstalleddocker pull reg.local.com/dev/web-demo:v1.0v1.0: Pulling from dev/web-demo7448db3b31eb: Pull completec36604fa7939: Pull complete29e8ef0e3340: Pull completea0c934d2565d: Pull completea360a17c9cab: Pull completecfcc996af805: Pull complete2cf014724202: Pull complete4bc402a00dfe: Pull complete7f506d2e6327: Pull complete577ef7ca6761: Pull completeDigest: sha256:80530996e66df715a51f3407423802a106271b1bc4267114d5a6cc5f9a0a87efStatus: Downloaded newer image for reg.local.com/dev/web-demo:v1.0reg.local.com/dev/web-demo:v1.0$ docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEreg.local.com/dev/web-demo v1.0 e03f3e0f181f 41 hours ago 677MBdocker run --publish 8888:8080 reg.local.com/dev/web-demo:v1.0 . ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v2.4.1)2021-01-06 17:41:12.950 INFO 1 --- [ main] com.local.demo.DemoApplication : Starting DemoApplication v0.0.1-SNAPSHOT using Java 1.8.0_111 on 8f2fb5b3f985 with PID 1 (/app.jar started by root in /)2021-01-06 17:41:12.957 INFO 1 --- [ main] com.local.demo.DemoApplication : No active profile set, falling back to default profiles: default2021-01-06 17:41:14.150 INFO 1 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)2021-01-06 17:41:14.160 INFO 1 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]2021-01-06 17:41:14.160 INFO 1 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.41]2021-01-06 17:41:14.212 INFO 1 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext2021-01-06 17:41:14.212 INFO 1 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1177 ms2021-01-06 17:41:14.476 INFO 1 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'2021-01-06 17:41:14.641 INFO 1 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''2021-01-06 17:41:14.651 INFO 1 --- [ main] com.local.demo.DemoApplication : Started DemoApplication in 2.136 seconds (JVM running for 2.486)2021-01-06 17:41:30.169 INFO 1 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet'2021-01-06 17:41:30.169 INFO 1 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'2021-01-06 17:41:30.170 INFO 1 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Completed initialization in 1 ms其他方式部署可以参考:k8s+jenkins实现自动化部署应用至k8s集群
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。