[关闭]
@zhangyy 2020-03-15T14:06:46.000000Z 字数 5210 阅读 169

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

kubernetes系列


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

一:系统初始化

1.1 系统主机名

  1. 192.168.100.11 node01.flyfish
  2. 192.168.100.12 node02.flyfish
  3. 192.168.100.13 node03.flyfish
  4. 192.168.100.14 node04.flyfish
  5. 192.168.100.15 node05.flyfish
  6. 192.168.100.16 node06.flyfish

image_1duhe14e91hte1gm81nqcdlc1gqna2.png-77.1kB


1.2 关闭firewalld 清空iptables 与 selinux 规则

  1. 系统节点全部执行:
  2. systemctl stop firewalld && systemctl disable firewalld && yum -y install iptables-services && systemctl start iptables && systemctl enable iptables && iptables -F && service iptables save
  1. 关闭 SELINUX
  2. swapoff -a && sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab
  3. setenforce 0 && sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/selinux/config

image_1dt2ssl4j1m715b2du7pr31l2ff.png-230.7kB

image_1dt2t3bdg1rk41r0s190kecdtdq23.png-66.3kB


1.3 安装 依赖包

  1. 全部节点安装
  2. 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

  1. 所有节点都执行
  2. cat > kubernetes.conf <<EOF
  3. net.bridge.bridge-nf-call-iptables=1
  4. net.bridge.bridge-nf-call-ip6tables=1
  5. net.ipv4.ip_forward=1
  6. net.ipv4.tcp_tw_recycle=0
  7. vm.swappiness=0 # 禁止使用 swap 空间,只有当系统 OOM 时才允许使用它 vm.overcommit_memory=1 # 不检查物理内存是否够用
  8. vm.panic_on_oom=0 # 开启 OOM
  9. fs.inotify.max_user_instances=8192
  10. fs.inotify.max_user_watches=1048576
  11. fs.file-max=52706963
  12. fs.nr_open=52706963
  13. net.ipv6.conf.all.disable_ipv6=1
  14. net.netfilter.nf_conntrack_max=2310720
  15. EOF
  16. cp kubernetes.conf /etc/sysctl.d/kubernetes.conf
  17. sysctl -p /etc/sysctl.d/kubernetes.conf

image_1dt2tjj4g9eduel18fbf7c1ofj3j.png-148.7kB

image_1dt2tk53ej2mtt010hd195dd1640.png-186.3kB


1.5 调整系统时区

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

1.6 关闭系统不需要服务

  1. systemctl stop postfix && systemctl disable postfix

image_1dt2tsmq91g6n1s9klui1c851j5s4d.png-72.3kB

1.7 设置 rsyslogd 和 systemd journald

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

image_1dt2ugl8apjk1uf4921am2s0i1g.png-150kB

1.7 升级系统内核为 4.44

  1. CentOS 7.x 系统自带的 3.10.x 内核存在一些 Bugs,导致运行的 DockerKubernetes 不稳定,例如: rpm -Uvh
  2. http://www.elrepo.org/elrepo-release-7.0-3.el7.elrepo.noarch.rpm
  3. rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-3.el7.elrepo.noarch.rpm
  4. # 安装完成后检查 /boot/grub2/grub.cfg 中对应内核 menuentry 中是否包含 initrd16 配置,如果没有,再安装 一次!
  5. yum --enablerepo=elrepo-kernel install -y kernel-lt
  6. # 设置开机从新内核启动
  7. grub2-set-default "CentOS Linux (4.4.182-1.el7.elrepo.x86_64) 7 (Core)"
  8. reboot
  9. # 重启后安装内核源文件
  10. 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的前置条件

  1. modprobe br_netfilter
  2. cat > /etc/sysconfig/modules/ipvs.modules <<EOF
  3. #!/bin/bash
  4. modprobe -- ip_vs
  5. modprobe -- ip_vs_rr
  6. modprobe -- ip_vs_wrr
  7. modprobe -- ip_vs_sh
  8. modprobe -- nf_conntrack_ipv4
  9. EOF
  10. chmod 755 /etc/sysconfig/modules/ipvs.modules
  11. bash /etc/sysconfig/modules/ipvs.modules
  12. lsmod | grep -e ip_vs -e nf_conntrack_ipv4

image_1dt2vpt1t1g7bulhkp11nve1acf44.png-188kB

二: 开始安装vmware harbor 集群

2.1 安装docker

  1. 机器节点都执行:
  2. yum install -y yum-utils device-mapper-persistent-data lvm2
  3. yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
  4. curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://abcd1234.m.daocloud.io
  5. yum update -y && yum install docker-ce-18.09.9 docker-ce-cli-18.09.9 containerd.io -y
  6. 重启机器: reboot
  7. 查看内核版本: uname -r
  8. 在加载: grub2-set-default "CentOS Linux (4.4.182-1.el7.elrepo.x86_64) 7 (Core)" && reboot
  9. 如果还不行
  10. 就改 文件 vim /etc/grub2.cfg 注释掉 3.10 内核
  11. 保证 内核的版本 4.4
  12. service docker start
  13. chkconfig docker on
  14. ## 创建 /etc/docker 目录
  15. mkdir /etc/docker
  16. # 配置 daemon.
  17. cat > /etc/docker/daemon.json <<EOF
  18. {
  19. "exec-opts": ["native.cgroupdriver=systemd"],
  20. "log-driver": "json-file",
  21. "log-opts": {
  22. "max-size": "100m"
  23. },
  24. "insecure-registries": ["https://node04.flyfish"],
  25. "registry-mirrors": ["https://registry.docker-cn.com","http://hub-mirror.c.163.com"]
  26. }
  27. EOF
  28. mkdir -p /etc/systemd/system/docker.service.d
  29. # 重启docker服务
  30. systemctl daemon-reload && systemctl restart docker && systemctl enable docker

  1. 上传: docker-compose harbor-offline-installer-v1.2.0.tgz
  2. mv docker-compose /usr/bin/
  3. chmod +x /usr/bin/docker-compose
  4. tar -zxvf harbor-offline-installer-v1.2.0.tgz

image_1dtvg1m5720hm8a44q9mfu519.png-35.7kB

image_1dtvgfgd8sod163vbh1jes1bo33.png-124.6kB

  1. mv harbor /usr/local/
  2. cd /usr/local/harbor/

image_1dtvgibqf1nebl10q9if8fsr33g.png-108.1kB

  1. vim harbor.cfg
  2. ---
  3. hostname node04.flyfish
  4. ---

image_1dtvgmrctsnc1qlh190p16af19om3t.png-54.1kB

  1. mkdir -p /data/cert/
  2. 创创建建 https 证证书书以以及及配配置置相相关关目目录录权权限限
  3. cd /data/cert/
  4. 创建私钥:
  5. openssl genrsa -des3 -out server.key 2048
  6. openssl req -new -key server.key -out server.csr
  7. cp server.key server.key.org
  8. openssl rsa -in server.key.org -out server.key
  9. openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
  10. 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

  1. cd /usr/local/harbor/
  2. ./install.sh

image_1dtvhnkv81o1i10a11l091uuql3e88.png-106.7kB

image_1dtvhpua21i0v1hfu1501spo6e38l.png-204.5kB

image_1dtvhr9bq1d6skk6iqm1ud7in992.png-152.4kB

image_1dtvhvindsa0t801asl1nl41cdc9f.png-278.5kB

  1. 登陆用户名密码:
  2. admin
  3. Harbor12345

image_1dtvi3aio101a321b9h1l3c8a39s.png-193.8kB

  1. 查看harbor 是否能用docker 登陆
  2. docker login https://node04.flyfish
  3. 用户名: admin
  4. 密码: Harbor12345

image_1dtvi8d46bfui6h1gn21osh1qioap.png-70.4kB

  1. docker pull wangyanglinux/myapp:v1
  2. docker pull wodby/nginx
  3. docker tag wodby/nginx node04.flyfish/library/wodby/nginx:v1
  4. docker push node04.flyfish/library/wodby/nginx:v1
  5. docker tag wangyanglinux/myapp:v1 node04.flyfish/library/myapp:v1
  6. 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_1dtvjfvip3841kgj1g1b1l5i12u7dn.png-167.3kB

  1. 删掉原来的镜像
  2. docker rmi -f wangyanglinux/myapp:v1
  3. docker rmi -f node04.flyfish/library/myapp:v1
  4. docker rmi -f wodby/nginx
  5. docker rmi -f node04.flyfish/library/wodby/nginx:v1

image_1dtvjkukj146i1u5n3td271ufje4.png-160.2kB

image_1dtvjqaak6it1tar1767kbf1ia1fh.png-161.9kB

三: 发布一个对外的nginx

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

image_1duharq661aj01m8g6hd1i8dfpn9.png-242kB

image_1duhau2n2c5g5qv4hn1p0fov1m.png-226.7kB

image_1duhb5nbkesdtib1b8admm12ft13.png-71.6kB


  1. 副本扩容:
  2. kubectl get deploy
  3. kubectl scale --replicas=3 deploy/nginx-deployment

image_1duhbf6ma1fbt6kf1dsjo751eak1g.png-84.3kB

image_1duhbiduqkblu8u16trbdc1klv2d.png-70.6kB

image_1duhbk1601m9g104aubp1ce9uu92q.png-110.1kB


  1. 暴露端口访问
  2. kubectl expose deployment nginx-deployment --port=3000 --target-port=80
  3. kubectl get svc

image_1duhckqn81nmhmnu46vkmr105t37.png-127kB

image_1duhcmqg21sg21qs0ssjoj1cf83k.png-110.9kB

image_1duhcncrm1kac5smo091g2q18s441.png-160.7kB

image_1duhco3srhsg9e6sm41skr1kq4e.png-176.4kB

  1. kubectl get pods -o wide

image_1duhcq8ugc791jkb1jpd1kkl1ebi4r.png-121.1kB

  1. kubectl edit svc nginx-deployment
  2. ---
  3. 修改TYPE 类型 clusterIP 变为:NodePort
  4. ---

image_1duhd0al413rnvij8911aqt68j6r.png-128.8kB

image_1duhcv63okov151q1qhn76nrmi6e.png-171.9kB

  1. kubectl get pod svc,pods -o wide

image_1duhd3b11t4g1b8m1ifiq086nv7o.png-128.4kB

  1. 从外网访问:
  2. node02.flyfish:30789
  3. node03.flyfish:30789

image_1duhd6fuk1ei5ink80ma411di285.png-74.7kB

image_1duhd93qbp0v125s12m112kb1tij95.png-62.3kB

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注