3、Kubernetes - 集群安装 - 配置私有仓库、集群功能演示

x33g5p2x  于2021-12-25 转载在 其他  
字(4.3k)|赞(0)|评价(0)|浏览(255)

创建harbor虚拟机:

设置repo

curl -o CentOS7-Base-163.repo http://mirrors.163.com/.help/CentOS7-Base-163.repo

设置系统主机名以及 Host 文件的相互解析

hostnamectl  set-hostname  harbor

安装依赖包

yum install -y conntrack ntpdate ntp ipvsadm ipset jq iptables curl sysstat libseccomp wget vim net-tools git

设置防火墙为 Iptables 并设置空规则

systemctl  stop firewalld  &&  systemctl  disable firewalld
yum -y install iptables-services  &&  systemctl  start iptables  
&&  systemctl  enable iptables &&  iptables -F  &&  service iptables save

关闭 SELINUX

swapoff -a && sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab
setenforce 0 && sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/selinux/config

调整系统时区

# 设置系统时区为中国/上海
timedatectl set-timezone Asia/Shanghai

# 将当前的 UTC 时间写入硬件时钟
timedatectl set-local-rtc 0

# 重启依赖于系统时间的服务
systemctl restart rsyslog

systemctl restart crond

#占位符

关闭系统不需要服务

systemctl stop postfix && systemctl disable postfix

设置 rsyslogd 和 systemd journald

mkdir /var/log/journal # 持久化保存日志的目录
mkdir /etc/systemd/journald.conf.d
 
cat > /etc/systemd/journald.conf.d/99-prophet.conf <<EOF
[Journal]
# 持久化保存到磁盘
Storage=persistent
 
# 压缩历史日志
Compress=yes
SyncIntervalSec=5m
RateLimitInterval=30s
RateLimitBurst=1000
 
# 最大占用空间 10G
SystemMaxUse=10G
 
# 单日志文件最大 200M
SystemMaxFileSize=200M
 
# 日志保存时间 2 周
MaxRetentionSec=2week
 
# 不将日志转发到 syslog
ForwardToSyslog=no
EOF
 
 
systemctl restart systemd-journald

安装 Docker 软件

yum install -y yum-utils device-mapper-persistent-data lvm2
 
yum-config-manager --add-repo  http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
 
yum update -y && yum install -y docker-ce
 
## 创建 /etc/docker 目录
mkdir /etc/docker
# 配置 daemon.
cat > /etc/docker/daemon.json <<EOF
{
   "exec-opts": ["native.cgroupdriver=systemd"],
   "log-driver": "json-file",
   "log-opts": {
      "max-size": "100m"
   }
}
EOF
 
systemctl enable docker && systemctl start docker
mkdir -p /etc/systemd/system/docker.service.d
 
# 重启docker服务
systemctl daemon-reload && systemctl restart docker && systemctl enable docker

上传docker-compose

链接:https://pan.baidu.com/s/1pKRRj0ZXomnj1IlJnFCr1Q 

提取码:nk7i

上传habor的tar包:harbor-offline-installer-v1.2.0.tgz

链接:https://pan.baidu.com/s/1ToOX3-GKEwT1nxgDvUqTLQ 

提取码:md4w

https://storage.googleapis.com/harbor-releases/release-1.10.0/harbor-offline-installer-v1.10.0.tgz

curl -L https://github.com/docker/compose/releases/download/1.25.4/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
mv docker-compose /usr/local/bin/
chmod a+x /usr/local/bin/docker-compose
tar -zxvf harbor-offline-installer-v1.2.0.tgz
mv harbor/ /usr/local/
cd /usr/local/harbor
ll /usr/local/harbor

Harbor 安装: Harbor 官方地址: https://github.com/vmware/harbor/releases

1、 解压软件包: tar xvf harbor-offline-installer-<version>.tgz

https://github.com/vmware/harbor/releases/download/v1.2.0/harbor-offline-installer-v1.2.0.tgz

2、 配置harbor.cfg

必选参数
hostname: 目标的主机名或者完全限定域名
ui_url_protocol: http或https。 默认为http
db_password: 用于db_auth的MySQL数据库的根密码。 更改此密码进行任何生产用途
max_job_workers: ( 默认值为3) 作业服务中的复制工作人员的最大数量。 对于每个映像复制作业,
工作人员将存储库的所有标签同步到远程目标。 增加此数字允许系统中更多的并发复制作业。 但是, 由于每个工
作人员都会消耗一定数量的网络/ CPU / IO资源, 请根据主机的硬件资源, 仔细选择该属性的值
customize_crt: ( on或off。 默认为on) 当此属性打开时, prepare脚本将为注册表的令牌的生成/验证创
建私钥和根证书
ssl_cert: SSL证书的路径, 仅当协议设置为https时才应用
ssl_cert_key: SSL密钥的路径, 仅当协议设置为https时才应用
secretkey_path: 用于在复制策略中加密或解密远程注册表的密码的密钥路径

3、创建 https 证书以及配置相关目录权限

mkdir -p /data/cert
chmod -R 777 /data/cert
openssl genrsa -des3 -out server.key 2048
openssl req -new -key server.key -out server.csr
cp server.key server.key.org
openssl rsa -in server.key.org -out server.key
openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt

4、 运行脚本进行安装

sh install.sh

5、 访问测试

https://reg.yourdomain.com的管理员门户( 将reg.yourdomain.com更改为您的主机名harbor.cfg里的域名) 。 请注意, 默
认管理员用户名/密码为admin / Harbor12345

6、在windows的hosts里配置ip与域名的映射关系

进入 C:\Windows\System32\drivers\etc
编辑C:\Windows\System32\drivers\etc\hosts文件:
192.168.60.100 hub.ljxwtl.com

6.1、 上传镜像进行上传测试

指定镜像仓库地址

vim /etc/docker/daemon.json

添加

"insecure-registries": ["http://hub.ljxwtl.com"]

#占位符

 

7、使用Harbor服务器

在其他节点上登录:

docker login https://hub.ljxwtl.com
docker pull nginx
docker push hub.ljxwtl.com/library/nginx:latest

vim /etc/docker/daemon.json

"insecure-registries": ["http://hub.ljxwtl.com"]

 kubectl expose service的ip和端口号

kubectl expose deployment nginx-linux --port=30000 --target-port=80

 将容器服务暴漏出外网访问端口

kubectl edit service nginx-linux

将type改成NodePort

这样就可以访问了!!!

http://192.168.66.10:30357

http://192.168.66.20:30357

http://192.168.66.21:30357

根据Dockfile打包镜像的说明

docker build -t onlysearch-v1.0 .

相关文章