K8S

Wesley13
• 阅读 765
  • 准备主机
  1. centos7镜像
  2. node1: 192.168.0.101
  3. node2: 192.168.0.102
  4. node3: 192.168.0.103
  5. vip: 192.168.0.104
  • 配置ssh免密 并修改/etc/hosts跟/etc/hostname

  • 配置所有节点的kubelet

    配置kubelet使用国内可用镜像

    修改/etc/systemd/system/kubelet.service.d/10-kubeadm.conf

    添加如下配置

    Environment="KUBELET_EXTRA_ARGS=--pod-infra-container-image=registry.cn-shanghai.aliyuncs.com/gcr-k8s/pause-amd64:3.0"

    使用命令

    sed -i '/ExecStart=$/i Environment="KUBELET_EXTRA_ARGS=--pod-infra-container-image=registry.cn-shanghai.aliyuncs.com/gcr-k8s/pause-amd64:3.0"' /etc/systemd/system/kubelet.service.d/10-kubeadm.conf

    重新载入配置

    systemctl daemon-reload

  • 修改环境变量

    rm -rf $HOME/.kube mkdir -p $HOME/.kube sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config sudo chown $(id -u):$(id -g) $HOME/.kube/config

    systemctl stop firewalld && systemctl disable firewalld

    setenforce 0 #临时禁用selinux sed -i "s/^SELINUX=enforcing/SELINUX=disabled/g" /etc/sysconfig/selinux #永久关闭 修改/etc/sysconfig/selinux文件设置 sed -i "s/^SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config

    swapoff -a #临时关闭swap sed -i 's/.swap./#&/' /etc/fstab #永久关闭 注释/etc/fstab文件里swap相关的行

    cat < /etc/sysctl.d/k8s.conf net.bridge.bridge-nf-call-ip6tables = 1 net.bridge.bridge-nf-call-iptables = 1 EOF sysctl --system

    cat < /etc/yum.repos.d/kubernetes.repo [kubernetes] name=Kubernetes baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64 enabled=1 gpgcheck=1 repo_gpgcheck=1 gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg EOF

    yum install -y kubelet-1.11.0 kubeadm-1.11.0 kubectl-1.11.0

  • 拉取镜像

    #新建脚本 images=(kube-proxy-amd64:v1.11.0 kube-scheduler-amd64:v1.11.0 kube-controller-manager-amd64:v1.11.0 kube-apiserver-amd64:v1.11.0 etcd-amd64:3.2.18 coredns:1.1.3 pause-amd64:3.1 kubernetes-dashboard-amd64:v1.8.3 k8s-dns-sidecar-amd64:1.14.9 k8s-dns-kube-dns-amd64:1.14.9 k8s-dns-dnsmasq-nanny-amd64:1.14.9 ) for imageName in ${images[@]} ; do docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/$imageName done

  • 部署keepalived跟haproxy

    新建脚本 每台master执行docker pull haproxy:1.7.8-alpine

    mkdir /etc/haproxy cat >/etc/haproxy/haproxy.cfg<<EOF global log 127.0.0.1 local0 err maxconn 5000 uid 99 gid 99 #daemon nbproc 1 pidfile haproxy.pid

    defaults mode http log 127.0.0.1 local0 err maxconn 5000 retries 3 timeout connect 5s timeout client 30s timeout server 30s timeout check 2s

    listen admin_stats mode http bind 0.0.0.0:1080 log 127.0.0.1 local0 err stats refresh 30s stats uri /haproxy-status stats realm Haproxy\ Statistics stats auth will:will stats hide-version stats admin if TRUE

    frontend k8s-https bind 0.0.0.0:8443 mode tcp #maxconn 50000 default_backend k8s-https

    backend k8s-https mode tcp balance roundrobin server k8s-master01 172.16.2.71:6443 weight 1 maxconn 1000 check inter 2000 rise 2 fall 3 server k8s-master02 172.16.2.72:6443 weight 1 maxconn 1000 check inter 2000 rise 2 fall 3 server k8s-master03 172.16.2.73:6443 weight 1 maxconn 1000 check inter 2000 rise 2 fall 3 EOF

    启动haproxy

    docker run -d --name my-haproxy
    -v /etc/haproxy:/usr/local/etc/haproxy:ro
    -p 8443:8443
    -p 1080:1080
    --restart always
    haproxy:1.7.8-alpine

    #keepalived docker pull osixia/keepalived:1.4.4 docker run --net=host --cap-add=NET_ADMIN
    -e KEEPALIVED_INTERFACE=ens33 \ #改成你的网卡名称 -e KEEPALIVED_VIRTUAL_IPS="#PYTHON2BASH:['192.168.0.104']"
    -e KEEPALIVED_UNICAST_PEERS="#PYTHON2BASH:['192.168.0.101,'192.168.0.102','192.168.0.103']"
    -e KEEPALIVED_PASSWORD=admin
    --name k8s-keepalived
    --restart always
    -d osixia/keepalived:1.4.4

  • 启动第一台master

    新建脚本 执行完成后保证master启动日志 含有node节点加入token命令LOAD_BALANCER_DNS="192.168.0.101"

    LOAD_BALANCER_PORT="8443" CP0_HOSTNAME="node1" CP0_IP="192.168.0.104" cat >kubeadm-config.yaml<<EOF apiVersion: kubeadm.k8s.io/v1alpha2 kind: MasterConfiguration kubernetesVersion: v1.11.0 imageRepository: registry.cn-hangzhou.aliyuncs.com/google_containers

    apiServerCertSANs:

    • "$LOAD_BALANCER_DNS"
    • "node1"
    • "node2"
    • "node3"
    • "192.168.0.101"
    • "192.168.0.102"
    • "192.168.0.103"
    • "192.168.0.104"
    • "127.0.0.1" api: controlPlaneEndpoint: "$LOAD_BALANCER_DNS:$LOAD_BALANCER_PORT" etcd: local: extraArgs: listen-client-urls: "https://127.0.0.1:2379,https://$CP0_IP:2379" advertise-client-urls: "https://$CP0_IP:2379" listen-peer-urls: "https://$CP0_IP:2380" initial-advertise-peer-urls: "https://$CP0_IP:2380" initial-cluster: "$CP0_HOSTNAME=https://$CP0_IP:2380" serverCertSANs: - $CP0_HOSTNAME - $CP0_IP peerCertSANs: - $CP0_HOSTNAME - $CP0_IP networking:

      This CIDR is a Calico default. Substitute or remove for your CNI provider.

      podSubnet: "192.168.0.0/16" EOF

    kubeadm init --config kubeadm-config.yaml > start.log

    cd /etc/kubernetes && tar cvzf k8s-key.tgz admin.conf pki/ca.* pki/sa.* pki/front-proxy-ca.* pki/etcd/ca.*

    scp k8s-key.tgz node2:~/

    scp k8s-key.tgz node1:~/

    ssh node2 'tar xf k8s-key.tgz -C /etc/kubernetes/'

    ssh node1 'tar xf k8s-key.tgz -C /etc/kubernetes/'

    rm -rf $HOME/.kube mkdir -p $HOME/.kube sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config sudo chown $(id -u):$(id -g) $HOME/.kube/config

  • 启动第二台master

    #新建脚本

    LOAD_BALANCER_DNS="192.168.0.104" LOAD_BALANCER_PORT="8443" CP0_HOSTNAME="node1" CP0_IP="192.168.0.101" CP1_HOSTNAME="node2" CP1_IP="192.168.0.102" cat >kubeadm-config.yaml<<EOF apiVersion: kubeadm.k8s.io/v1alpha2 kind: MasterConfiguration kubernetesVersion: v1.11.0 imageRepository: registry.cn-hangzhou.aliyuncs.com/google_containers apiServerCertSANs:

    • "$LOAD_BALANCER_DNS"
    • "node1"
    • "node2"
    • "node3"
    • "192.168.0.101"
    • "192.168.0.102"
    • "192.168.0.103"
    • "192.168.0.104"
    • "127.0.0.1" api: controlPlaneEndpoint: "$LOAD_BALANCER_DNS:$LOAD_BALANCER_PORT" etcd: local: extraArgs: listen-client-urls: "https://127.0.0.1:2379,https://$CP1_IP:2379" advertise-client-urls: "https://$CP1_IP:2379" listen-peer-urls: "https://$CP1_IP:2380" initial-advertise-peer-urls: "https://$CP1_IP:2380" initial-cluster: "$CP0_HOSTNAME=https://$CP0_IP:2380,$CP1_HOSTNAME=https://$CP1_IP:2380" initial-cluster-state: existing serverCertSANs: - $CP1_HOSTNAME - $CP1_IP peerCertSANs: - $CP1_HOSTNAME - $CP1_IP networking:

      This CIDR is a calico default. Substitute or remove for your CNI provider.

      podSubnet: "192.168.0.0/16" EOF

    kubeadm alpha phase certs all --config kubeadm-config.yaml kubeadm alpha phase kubelet config write-to-disk --config kubeadm-config.yaml kubeadm alpha phase kubelet write-env-file --config kubeadm-config.yaml kubeadm alpha phase kubeconfig kubelet --config kubeadm-config.yaml systemctl start kubelet KUBECONFIG=/etc/kubernetes/admin.conf kubectl exec -n kube-system etcd-${CP0_HOSTNAME} -- etcdctl --ca-file /etc/kubernetes/pki/etcd/ca.crt --cert-file /etc/kubernetes/pki/etcd/peer.crt --key-file /etc/kubernetes/pki/etcd/peer.key --endpoints=https://${CP0_IP}:2379 member add ${CP1_HOSTNAME} https://${CP1_IP}:2380 kubeadm alpha phase etcd local --config kubeadm-config.yaml kubeadm alpha phase kubeconfig all --config kubeadm-config.yaml kubeadm alpha phase controlplane all --config kubeadm-config.yaml kubeadm alpha phase mark-master --config kubeadm-config.yaml

  • 部署第三台master

    新建脚本

    LOAD_BALANCER_DNS="192.168.91.100" LOAD_BALANCER_PORT="8443" CP0_HOSTNAME="node1" CP0_IP="192.168.0.101" CP1_HOSTNAME="node2" CP1_IP="192.168.0.102" CP2_HOSTNAME="node3" CP2_IP="192.168.0.103" cat >kubeadm-config.yaml<<EOF apiVersion: kubeadm.k8s.io/v1alpha2 kind: MasterConfiguration kubernetesVersion: v1.11.0 imageRepository: registry.cn-hangzhou.aliyuncs.com/google_containers piServerCertSANs:

    • "$LOAD_BALANCER_DNS"
    • "node1"
    • "node2"
    • "node3"
    • "192.168.0.101"
    • "192.168.0.102"
    • "192.168.0.103"
    • "192.168.0.104"
    • "127.0.0.1" api: controlPlaneEndpoint: "$LOAD_BALANCER_DNS:$LOAD_BALANCER_PORT" etcd: local: extraArgs: listen-client-urls: "https://127.0.0.1:2379,https://$CP2_IP:2379" advertise-client-urls: "https://$CP2_IP:2379" listen-peer-urls: "https://$CP2_IP:2380" initial-advertise-peer-urls: "https://$CP2_IP:2380" initial-cluster: "$CP0_HOSTNAME=https://$CP0_IP:2380,$CP1_HOSTNAME=https://$CP1_IP:2380,$CP2_HOSTNAME=https://$CP2_IP:2380" initial-cluster-state: existing serverCertSANs: - $CP2_HOSTNAME - $CP2_IP peerCertSANs: - $CP2_HOSTNAME - $CP2_IP networking:

      This CIDR is a calico default. Substitute or remove for your CNI provider.

      podSubnet: "192.168.0.0/16" EOF

    kubeadm alpha phase certs all --config kubeadm-config.yaml kubeadm alpha phase kubelet config write-to-disk --config kubeadm-config.yaml kubeadm alpha phase kubelet write-env-file --config kubeadm-config.yaml kubeadm alpha phase kubeconfig kubelet --config kubeadm-config.yaml systemctl start kubelet KUBECONFIG=/etc/kubernetes/admin.conf kubectl exec -n kube-system etcd-${CP0_HOSTNAME} -- etcdctl --ca-file /etc/kubernetes/pki/etcd/ca.crt --cert-file /etc/kubernetes/pki/etcd/peer.crt --key-file /etc/kubernetes/pki/etcd/peer.key --endpoints=https://${CP0_IP}:2379 member add ${CP2_HOSTNAME} https://${CP2_IP}:2380 kubeadm alpha phase etcd local --config kubeadm-config.yaml kubeadm alpha phase kubeconfig all --config kubeadm-config.yaml kubeadm alpha phase controlplane all --config kubeadm-config.yaml kubeadm alpha phase mark-master --config kubeadm-config.yaml

  • 部署网络可以使用calico或者flannel

    #新建脚本 wget https://docs.projectcalico.org/v3.1/getting-started/kubernetes/installation/hosted/rbac-kdd.yaml

    wget https://docs.projectcalico.org/v3.1/getting-started/kubernetes/installation/hosted/kubernetes-datastore/calico-networking/1.7/calico.yaml #每个master节点执行 calico使用DaemonSet部署到每个node kubectl taint nodes --all node-role.kubernetes.io/master- kubectl apply -f rbac-kdd.yaml kubectl apply -f calico.yaml#查看master节点状况kubectl get pods --all-namespaces

  • 加入node节点

    #第一台master执行完 start.log找出token命令
      kubeadm join 192.168.0.104:8443 --token v8q1a2.9zb56bff4076tmin --discovery-token-ca-cert-hash sha256:94a1bc52ce95cb8a69c97528d81ca0ea2bde48947450b9c7b59225dcafe8cebc
    
点赞
收藏
评论区
推荐文章
blmius blmius
3年前
MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1
文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s
皕杰报表之UUID
​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为
待兔 待兔
5个月前
手写Java HashMap源码
HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22
Jacquelyn38 Jacquelyn38
3年前
2020年前端实用代码段,为你的工作保驾护航
有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )
Stella981 Stella981
3年前
KVM调整cpu和内存
一.修改kvm虚拟机的配置1、virsheditcentos7找到“memory”和“vcpu”标签,将<namecentos7</name<uuid2220a6d1a36a4fbb8523e078b3dfe795</uuid
Wesley13 Wesley13
3年前
mysql设置时区
mysql设置时区mysql\_query("SETtime\_zone'8:00'")ordie('时区设置失败,请联系管理员!');中国在东8区所以加8方法二:selectcount(user\_id)asdevice,CONVERT\_TZ(FROM\_UNIXTIME(reg\_time),'08:00','0
Wesley13 Wesley13
3年前
00:Java简单了解
浅谈Java之概述Java是SUN(StanfordUniversityNetwork),斯坦福大学网络公司)1995年推出的一门高级编程语言。Java是一种面向Internet的编程语言。随着Java技术在web方面的不断成熟,已经成为Web应用程序的首选开发语言。Java是简单易学,完全面向对象,安全可靠,与平台无关的编程语言。
Stella981 Stella981
3年前
Django中Admin中的一些参数配置
设置在列表中显示的字段,id为django模型默认的主键list_display('id','name','sex','profession','email','qq','phone','status','create_time')设置在列表可编辑字段list_editable
Wesley13 Wesley13
3年前
MySQL部分从库上面因为大量的临时表tmp_table造成慢查询
背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_
Python进阶者 Python进阶者
11个月前
Excel中这日期老是出来00:00:00,怎么用Pandas把这个去除
大家好,我是皮皮。一、前言前几天在Python白银交流群【上海新年人】问了一个Pandas数据筛选的问题。问题如下:这日期老是出来00:00:00,怎么把这个去除。二、实现过程后来【论草莓如何成为冻干莓】给了一个思路和代码如下:pd.toexcel之前把这