kubernetes的的私有仓库vmware harbor的配置

标签(空格分隔): kubernetes系列


  • 一. 系统环境的配置
  • 二. vmware harbor 的安装测试
  • 三. 发布一个测试nginx

一:系统初始化

1.1 系统主机名

192.168.100.11  node01.flyfish
192.168.100.12  node02.flyfish
192.168.100.13  node03.flyfish
192.168.100.14  node04.flyfish
192.168.100.15  node05.flyfish
192.168.100.16  node06.flyfish

image_1duhe14e91hte1gm81nqcdlc1gqna2.png-77.1kB


1.2 关闭firewalld 清空iptables 与 selinux 规则

系统节点全部执行:

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

image_1dt2ssl4j1m715b2du7pr31l2ff.png-230.7kB

image_1dt2t3bdg1rk41r0s190kecdtdq23.png-66.3kB


1.3 安装 依赖包

全部节点安装

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

image_1dt2svjhtrii27cuu2eug1dbc19.png-279.7kB

image_1dt2t6djs1ia0t701tgc8afbd22g.png-384.2kB

1.4 升级调整内核参数,对于 K8S

所有节点都执行

cat > kubernetes.conf <<EOF

net.bridge.bridge-nf-call-iptables=1 
net.bridge.bridge-nf-call-ip6tables=1 
net.ipv4.ip_forward=1 
net.ipv4.tcp_tw_recycle=0 
vm.swappiness=0 # 禁止使用 swap 空间,只有当系统 OOM 时才允许使用它 vm.overcommit_memory=1 # 不检查物理内存是否够用 
vm.panic_on_oom=0 # 开启 OOM 
fs.inotify.max_user_instances=8192 
fs.inotify.max_user_watches=1048576 
fs.file-max=52706963 
fs.nr_open=52706963 
net.ipv6.conf.all.disable_ipv6=1 
net.netfilter.nf_conntrack_max=2310720

EOF 

cp kubernetes.conf /etc/sysctl.d/kubernetes.conf 
sysctl -p /etc/sysctl.d/kubernetes.conf

image_1dt2tjj4g9eduel18fbf7c1ofj3j.png-148.7kB

image_1dt2tk53ej2mtt010hd195dd1640.png-186.3kB


1.5 调整系统时区

# 设置系统时区为 中国/大发棋牌大发棋牌技巧技巧
上海
 timedatectl set-timezone Asia/Shanghai 
# 将当前的 UTC 时间写入硬件时钟 timedatectl set-local-rtc 0 
# 重启依赖于系统时间的大发棋牌大发棋牌技巧技巧
服务
 
systemctl restart rsyslog && systemctl restart crond

###1.6 关闭系统不需要大发棋牌大发棋牌技巧技巧 服务

systemctl stop postfix && systemctl disable postfix

image_1dt2tsmq91g6n1s9klui1c851j5s4d.png-72.3kB

###1.7 设置 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

image_1dt2ugl8apjk1uf4921am2s0i1g.png-150kB

1.7 升级系统内核为 4.44

CentOS 7.x 系统自带的 3.10.x 内核存在一些 Bugs,导致运行的 Docker、Kubernetes 不稳定,例如: rpm -Uvh
http://www.elrepo.org/elrepo-release-7.0-3.el7.elrepo.noarch.rpm

rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-3.el7.elrepo.noarch.rpm 
# 安装完成后检查 /boot/grub2/grub.cfg 中对应内核 menuentry 中是否包含 initrd16 配置,如果没有,再安装 一次! 
yum --enablerepo=elrepo-kernel install -y kernel-lt 
# 设置开机从新内核启动 
grub2-set-default "CentOS Linux (4.4.182-1.el7.elrepo.x86_64) 7 (Core)" 

reboot
# 重启后安装内核源文件 
yum --enablerepo=elrepo-kernel install kernel-lt-devel-$(uname -r) kernel-lt-headers-$(uname -r)

image_1dt2uvsadhr1teqkqf11iu11qe2d.png-129.2kB

image_1dt2v0mbv1h2q11cq4v1ooj2m32q.png-215.2kB

image_1dt2velm4c9i1v4rg4goqv1fkl37.png-92.5kB

image_1dt2vgk5hhk3tf9ss31mp7enn3k.png-39.1kB

1.8 kube-proxy开启ipvs的前置条件

modprobe br_netfilter 

cat > /etc/sysconfig/modules/ipvs.modules <<EOF 

#!/bin/bash 
modprobe -- ip_vs 
modprobe -- ip_vs_rr 
modprobe -- ip_vs_wrr 
modprobe -- ip_vs_sh 
modprobe -- nf_conntrack_ipv4 
EOF 

chmod 755 /etc/sysconfig/modules/ipvs.modules 

bash /etc/sysconfig/modules/ipvs.modules 

lsmod | grep -e ip_vs -e nf_conntrack_ipv4

image_1dt2vpt1t1g7bulhkp11nve1acf44.png-188kB

二: 开始安装vmware harbor 集群

2.1 安装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-18.09.9-3.el7 

重启机器: reboot 

查看内核版本: uname -r 

在加载: grub2-set-default "CentOS Linux (4.4.182-1.el7.elrepo.x86_64) 7 (Core)"  && reboot
如果还不行 
就改 文件 : vim /etc/grub2.cfg  注释掉 3.10 的 内核

保证 内核的版本 为 4.4 

service docker start 
chkconfig docker on 

## 创建 /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"
},

"insecure-registries":["http://node04.flyfish"]

}

EOF 

mkdir -p /etc/systemd/system/docker.service.d 

# 重启docker大发棋牌大发棋牌技巧技巧
服务
 

systemctl daemon-reload && systemctl restart docker && systemctl enable docker

上传: docker-compose 与harbor-offline-installer-v1.2.0.tgz 

mv docker-compose /usr/bin/
chmod +x /usr/bin/docker-compose

tar -zxvf harbor-offline-installer-v1.2.0.tgz 

image_1dtvg1m5720hm8a44q9mfu519.png-35.7kB

image_1dtvgfgd8sod163vbh1jes1bo33.png-124.6kB

mv harbor /usr/local/

cd /usr/local/harbor/

image_1dtvgibqf1nebl10q9if8fsr33g.png-108.1kB

vim harbor.cfg

---
hostname node04.flyfish
---

image_1dtvgmrctsnc1qlh190p16af19om3t.png-54.1kB

mkdir -p /data/cert/

创创建建 https 证证书书以以及及配配置置相相关关目目录录权权限限
cd /data/cert/
创建私钥:

openssl rq -new -key server.key -out server.csr

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

chmod 777 -R * 

image_1dtvgo5q32tb1qfd16rp92p7o34a.png-18kB

image_1dtvh08a6k8h11rb1jlkt86quv4n.png-88.4kB

image_1dtvh9u6rhime6q786b1om0b54.png-148.8kB

image_1dtvhimqp1t4t7du1vnfcqe19d661.png-79.8kB

image_1dtvhj8hr12vkib71mm2pfq1c086e.png-58.2kB

image_1dtvhm4tb10a0elr10f816261deh7r.png-55kB

cd /usr/local/harbor/

./install.sh

image_1dtvhnkv81o1i10a11l091uuql3e88.png-106.7kB

image_1dtvhpua21i0v1hfu1501spo6e38l.png-204.5kB

image_1dtvhr9bq1d6skk6iqm1ud7in992.png-152.4kB

image_1dtvhvindsa0t801asl1nl41cdc9f.png-278.5kB

登陆用户名密码:

admin
Harbor12345

image_1dtvi3aio101a321b9h1l3c8a39s.png-193.8kB

查看harbor 是否能用docker 登陆

docker login http://node04.flyfish
用户名: admin
密码: Harbor12345

image_1dtvi8d46bfui6h1gn21osh1qioap.png-70.4kB

docker pull wangyanglinux/myapp:v1
docker pull wodby/nginx
docker tag wodby/nginx node04.flyfish/library/wodby/nginx:v1
docker push node04.flyfish/library/wodby/nginx:v1
docker tag wangyanglinux/myapp:v1 node04.flyfish/library/myapp:v1
docker push node04.flyfish/library/myapp:v1

image_1dtvj3os6dbh7uqmj07g21k16bm.png-125.5kB

image_1dtvjd576bog1hm1102d1b1h1j67c3.png-101.4kB

image_1dtvje5md1270n2j10qh1sl11cdscg.png-107.5kB

image_1dtvjelje1aa1b2aha0s75uf1ct.png-228.6kB

image_1dtvjf7mqo801gkb1umm1hv6l24da.png-105.8kB

image_1dtvjf大发棋牌大发棋牌技巧技巧
vip
3841kgj1g1b1l5i12u7dn.png-167.3kB

删掉原来的镜像

docker rmi -f wangyanglinux/myapp:v1

docker rmi -f node04.flyfish/library/myapp:v1

docker rmi -f wodby/nginx

docker rmi -f node04.flyfish/library/wodby/nginx:v1

image_1dtvjkukj146i1u5n3td271ufje4.png-160.2kB

image_1dtvjqaak6it1tar1767kbf1ia1fh.png-161.9kB

三: 发布一个对外的nginx

测试从仓库(vmware harbor)创建一个pod测试
kubectl run nginx-deployment --image=node04.flyfish/library/myapp:v1 --port 80 --replicas=1

kubectl get pods

kubectl get deploy,rs

image_1duharq661aj01m8g6hd1i8dfpn9.png-242kB

image_1duhau2n2c5g5qv4hn1p0fov1m.png-226.7kB

image_1duhb5nbkesdtib1b8admm12ft13.png-71.6kB


副本扩容:

kubectl get deploy

kubectl scale --replicas=3 deploy/nginx-deployment

image_1duhbf6ma1fbt6kf1dsjo751eak1g.png-84.3kB

image_1duhbiduqkblu8u16trbdc1klv2d.png-70.6kB

image_1duhbk1601m9g104aubp1ce9uu92q.png-110.1kB


暴露端口访问

kubectl expose deployment nginx-deployment --port=3000 --target-port=80

kubectl get svc 

image_1duhckqn81nmhmnu46vkmr105t37.png-127kB

image_1duhcmqg21sg21qs0ssjoj1cf83k.png-110.9kB

image_1duhcncrm1kac5smo091g2q18s441.png-160.7kB

image_1duhco3srhsg9e6sm41skr1kq4e.png-176.4kB

kubectl get pods -o wide 

image_1duhcq8ugc791jkb1jpd1kkl1ebi4r.png-121.1kB

kubectl edit svc nginx-deployment
---
修改TYPE 类型 clusterIP 变为:NodePort
---

image_1duhd0al413rnvij8911aqt68j6r.png-128.8kB

image_1duhcv63okov151q1qhn76nrmi6e.png-171.9kB

kubectl get pod svc,pods -o wide 

image_1duhd3b11t4g1b8m1ifiq086nv7o.png-128.4kB

从外网访问:
node02.flyfish:30789

node03.flyfish:30789

image_1duhd6fuk1ei5ink80ma411di285.png-74.7kB

image_1duhd93qbp0v125s12m112kb1tij95.png-62.3kB