Kubernetes集群部署之五node节点部署

部署kubelet:

1.二进制包准备 将软件包可执行文件从k8s-master复制到node节点中去。

[[email protected] ~]# cd /usr/local/src/kubernetes/server/bin
[[email protected]-master bin]# scp kubelet kube-proxy 10.200.3.106:/opt/kubernetes/bin/
[[email protected]-master bin]# scp kubelet kube-proxy 10.200.3.107:/opt/kubernetes/bin/

2.创建角色绑定

[[email protected] ~]# cd /usr/local/src/ssl/
[[email protected]-master ssl]#  kubectl create clusterrolebinding kubelet-bootstrap   --clusterrole=system:node-bootstrapper   --user=kubelet-bootstrap

clusterrolebinding "kubelet-bootstrap" createdclusterrolebinding.rbac.authorization.k8s.io "kubelet-bootstrap" created

3.创建 kubelet bootstrapping kubeconfig 文件 设置集群参数

[[email protected] ssl]#  kubectl config set-cluster kubernetes    --certificate-authority=/opt/kubernetes/ssl/ca.pem    --embed-certs=true    --server=https://10.200.3.105:6443 \
   --kubeconfig=bootstrap.kubeconfig

Cluster "kubernetes" set.

4.设置客户端认证参数

[[email protected] ssl]# kubectl config set-credentials kubelet-bootstrap    --token=10a89e49bc403bce8fb134e5a2ae82f1    --kubeconfig=bootstrap.kubeconfig

User "kubelet-bootstrap" set.

5.设置上下文参数

[[email protected] ssl]# kubectl config set-context default    --cluster=kubernetes    --user=kubelet-bootstrap    --kubeconfig=bootstrap.kubeconfig

Context "default" created.

6.选择默认上下文并向node节点分发在master端生成的bootstrap.kubeconfig文件.

[[email protected] ssl]# kubectl config use-context default --kubeconfig=bootstrap.kubeconfig
Switched to context "default".

[[email protected]-master ssl]# cp bootstrap.kubeconfig /opt/kubernetes/cfg
[[email protected]-master ssl]# scp bootstrap.kubeconfig 10.200.3.106:/opt/kubernetes/cfg
[[email protected]-master ssl]# scp bootstrap.kubeconfig 10.200.3.107:/opt/kubernetes/cfg

部署kubelet(node节点操作).

1.设置CNI支持.

[[email protected]1 ~]# mkdir -p /etc/cni/net.d
[[email protected]-node-1 ~]# cat >/etc/cni/net.d/10-default.conf >>EOF
me": "flannel",
        "type": "flannel",
        "delegate": {
            "bridge": "docker0",
            "isDefaultGateway": true,
            "mtu": 1400
        }
}

2.创建kubelet目录

[[email protected]1 ~]# mkdir /var/lib/kubelet

3.创建kubelet服务配置

[[email protected]1 ~]# cat > /usr/lib/systemd/system/kubelet.service >>EOF
[Unit]
Description=Kubernetes Kubelet
Documentation=https://github.com/GoogleCloudPlatform/kubernetes
After=docker.service
Requires=docker.service

[Service]
WorkingDirectory=/var/lib/kubelet
ExecStart=/opt/kubernetes/bin/kubelet   --address=10.200.3.106   --hostname-override=10.200.3.106   --pod-infra-container-image=mirrorgooglecontainers/pause-amd64:3.0   --experimental-bootstrap-kubeconfig=/opt/kubernetes/cfg/bootstrap.kubeconfig   --kubeconfig=/opt/kubernetes/cfg/kubelet.kubeconfig   --cert-dir=/opt/kubernetes/ssl   --network-plugin=cni   --cni-conf-dir=/etc/cni/net.d   --cni-bin-dir=/opt/kubernetes/bin/cni   --cluster-dns=10.1.0.2   --cluster-domain=cluster.local.   --hairpin-mode hairpin-veth   --allow-privileged=true   --fail-swap-on=false   --logtostderr=true   --v=2   --logtostderr=false   --log-dir=/opt/kubernetes/log
Restart=on-failure
RestartSec=5

EOF

4.启动Kubelet

[[email protected]1 ~]# systemctl daemon-reload
[[email protected]-node-1 ~]# systemctl enable kubelet
[[email protected]-node-1 ~]# systemctl start kubelet
[[email protected]-node-1 ~]# systemctl status kubelet

5.查看csr请求 注意是在k8s-maste上执行

[[email protected] ssl]# kubectl get csr
NAME                                                   AGE       REQUESTOR           CONDITION
node-csr-exRV4L4JbdyoO62eNEcTnSK7ehYji_47xhkU7e5-L5c   43s       kubelet-bootstrap   Pending

6.批准kubelet 的 TLS 证书请求

[[email protected] ssl]# kubectl get csr|grep ‘Pending‘ | awk ‘NR>0{print $1}‘| xargs kubectl certificate approve
certificatesigningrequest.certificates.k8s.io "node-csr-exRV4L4JbdyoO62eNEcTnSK7ehYji_47xhkU7e5-L5c" approved

执行完毕后,查看节点状态如果是Ready的状态就说明一切正常.

[[email protected] ~]# kubectl get node
NAME           STATUS    ROLES     AGE       VERSION
10.200.3.106   Ready     <none>    1d        v1.10.1

部署Kubernetes Proxy

1.配置kube-proxy使用LVS

# yum install -y ipvsadm ipset conntrack

2.创建 kube-proxy 证书请求

[[email protected] ~]# cd /usr/local/src/ssl/
[[email protected]-master ssl]# cat > kube-proxy-csr.json >>EOF

{
  "CN": "system:kube-proxy",
  "hosts": [],
  "key": {
    "algo": "rsa",
    "size": 2048
  },
  "names": [
    {
      "C": "CN",
      "ST": "BeiJing",
      "L": "BeiJing",
      "O": "k8s",
      "OU": "System"
    }
  ]
}

EOF

3.生成证书,并分发至node节点.

[[email protected] ssl]#cfssl gencert -ca=/opt/kubernetes/ssl/ca.pem    -ca-key=/opt/kubernetes/ssl/ca-key.pem    -config=/opt/kubernetes/ssl/ca-config.json    -profile=kubernetes  kube-proxy-csr.json | cfssljson -bare kube-proxy

[[email protected]-master ssl]# cp kube-proxy*.pem /opt/kubernetes/ssl/
[[email protected]-master ssl]# scp kube-proxy*.pem 10.200.3.106:/opt/kubernetes/ssl/
[[email protected]-master ssl]# scp kube-proxy*.pem 10.200.3.107:/opt/kubernetes/ssl/

4.创建kube-proxy配置文件

[[email protected] ssl]# kubectl config set-cluster kubernetes    --certificate-authority=/opt/kubernetes/ssl/ca.pem    --embed-certs=true    --server=https://10.200.3.105:6443 \
   --kubeconfig=kube-proxy.kubeconfig

Cluster "kubernetes" set.

[[email protected]-master ssl]#kubectl config set-credentials kube-proxy    --client-certificate=/opt/kubernetes/ssl/kube-proxy.pem    --client-key=/opt/kubernetes/ssl/kube-proxy-key.pem    --embed-certs=true    --kubeconfig=kube-proxy.kubeconfig

User "kube-proxy" set.

[[email protected]-master ssl]#kubectl config set-context default    --cluster=kubernetes    --user=kube-proxy    --kubeconfig=kube-proxy.kubeconfig
Context "default" created.

[[email protected]-master ssl]# kubectl config use-context default --kubeconfig=kube-proxy.kubeconfig
Switched to context "default".

6.分发kubeconfig配置文件到各节点.

[[email protected] ssl]# cp kube-proxy.kubeconfig /opt/kubernetes/cfg/
[[email protected]-master ssl]# scp kube-proxy.kubeconfig 10.200.3.106:/opt/kubernetes/cfg/
[[email protected]-master ssl]# scp kube-proxy.kubeconfig 10.200.3.107:/opt/kubernetes/cfg/

7.创建kube-proxy服务配置

[[email protected]1 ~]# mkdir /var/lib/kube-proxy
[[email protected]-node-1 ~]# cat > /usr/lib/systemd/system/kube-proxy.service >>EOF

[Unit]
Description=Kubernetes Kube-Proxy Server
Documentation=https://github.com/GoogleCloudPlatform/kubernetes
After=network.target

[Service]
WorkingDirectory=/var/lib/kube-proxy
ExecStart=/opt/kubernetes/bin/kube-proxy   --bind-address=10.200.3.106   --hostname-override=10.200.3.106   --kubeconfig=/opt/kubernetes/cfg/kube-proxy.kubeconfig --masquerade-all   --feature-gates=SupportIPVSProxyMode=true   --proxy-mode=ipvs   --ipvs-min-sync-period=5s   --ipvs-sync-period=5s   --ipvs-scheduler=rr   --logtostderr=true   --v=2   --logtostderr=false   --log-dir=/opt/kubernetes/log

Restart=on-failure
RestartSec=5
LimitNOFILE=65536

[Install]
WantedBy=multi-user.target

EOF

8.启动Kubernetes Proxy

[[email protected]1 ~]# systemctl daemon-reload
[[email protected]-node-1 ~]# systemctl enable kube-proxy
[[email protected]-node-1 ~]# systemctl start kube-proxy
[[email protected]-node-1 ~]# systemctl status kube-proxy

9.检查LVS状态

[[email protected]1 ~]# ipvsadm -L -n
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
TCP  10.1.0.1:443 rr persistent 10800
  -> 10.200.3.105:6443            Masq    1      0          0
[[email protected]-node-1 ~]# 

如果你在两台实验机器都安装了kubelet和proxy服务,使用下面的命令可以检查状态:

[[email protected] ~]# kubectl get nodes

NAME           STATUS    ROLES     AGE       VERSION
10.200.3.106   Ready     <none>    3h        v1.10.1
10.200.3.107   Ready     <none>    29m       v1.10.1

原文地址:https://www.cnblogs.com/saneri/p/9123712.html

时间: 2024-10-31 22:38:07

Kubernetes集群部署之五node节点部署的相关文章

Kubernetes容器集群管理环境 - Node节点的移除与加入

一.如何从Kubernetes集群中移除Node 比如从集群中移除k8s-node03这个Node节点,做法如下: 1)先在master节点查看Node情况 [[email protected]-master01 ~]# kubectl get nodes NAME STATUS ROLES AGE VERSION k8s-node01 Ready <none> 47d v1.14.2 k8s-node02 Ready <none> 47d v1.14.2 k8s-node03 R

部署k8s ssl集群实践14:work节点部署kube-proxy

二进制文件前面已经下载分发好. 6.1创建kube-proxy证书 创建证书签名请求 [[email protected] kube-proxy]# cat kube-proxy-csr.json { "CN": "system:kube-proxy", "key": { "algo": "rsa", "size": 2048 }, "names": [ { &quo

Kubeadm部署Kubernetes集群

Kubeadm部署Kubernetes1.14.1集群 原理kubeadm做为集群安装的"最佳实践"工具,目标是通过必要的步骤来提供一个最小可用的集群运行环境.它会启动集群的基本组件以及必要的附属组件,至于为集群提供更丰富功能(比如监控,度量)的组件,不在其安装部署的范围.在环境节点符合其基本要求的前提下,kubeadm只需要两条基本命令便可以快捷的将一套集群部署起来.这两条命令分别是: kubeadm init:初始化集群并启动master相关组件,在计划用做master的节点上执行

部署Bookinfo示例程序详细过程和步骤(基于Kubernetes集群+Istio v1.0)

部署Bookinfo示例程序详细过程和步骤(基于Kubernetes集群+Istio v1.0) 部署Bookinfo示例程序 在下载的Istio安装包的samples目录中包含了示例应用程序. Bookinfo应用 部署一个样例应用,它由四个单独的微服务构成,用来演示多种 Istio 特性.这个应用模仿在线书店的一个分类,显示一本书的信息.页面上会显示一本书的描述,书籍的细节(ISBN.页数等),以及关于这本书的一些评论. Bookinfo 应用分为四个单独的微服务: productpage

Rancher2.x 一键式部署 Prometheus + Grafana 监控 Kubernetes 集群

目录 1.Prometheus & Grafana 介绍 2.环境.软件准备 3.Rancher 2.x 应用商店 4.一键式部署 Prometheus 5.验证 Prometheus + Grafana 1.Prometheus & Grafana 介绍 Prometheus 是一套开源的系统监控.报警.时间序列数据库的组合,Prometheus 基本原理是通过 Http 协议周期性抓取被监控组件的状态,而通过 Exporter Http 接口输出这些被监控的组件信息,而且已经有很多 E

向Kubernetes集群添加/删除Node

向Kubernetes集群添加/移除Node Minion Node操作前准备 #关闭防火墙 systemctl stop firewalld #禁止防火墙开机启动 systemctl disable firewalld #检查selinux getenforce Disabled #端口检查 Kubernetes集群中添加Node在kubeadm init初始化操作完成时,系统最后给出了将节点加入集群的命令: kubeadm join 10.0.0.39:6443 --token 4g0p8w

kubernetes集群新增node

kubernetes集群要新增node,首先要配置ssh免密登陆 [email protected]:/etc/ansible# ssh-copy-id 172.18.196.6 /usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub" /usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s),

在 Linux 部署多节点 Kubernetes 集群与 KubeSphere 容器平台

KubeSphere 是在 Kubernetes 之上构建的以应用为中心的企业级容器平台,所有供为用户提供简单易用的操作界面以及向导式操作方式.同时,KubeSphere Installer 提供了 快速部署生产级别的 Kubernetes 集群和全栈化容器平台的功能,能够快速帮助企业用户快速搭建一套以应用为中心的 DevOps 平台. KubeSphere 支持部署和运行在包括公有云.私有云.VM.BM 和 Kubernetes 等任何基础设施之上,可以部署在公有云托管的 Kubernetes

Kubernetes 集群的两种部署过程(daemon部署和容器化部署)以及glusterfs的应用!

ClusterIp:通过VIP来访问, NodePort: 需要自己搭建负载据衡器 LoadBalancer:仅仅用于特定的云提供商 和 Google Container Engine https://www.nginx.com/blog/load-balancing-kubernetes-services-nginx-plus/ port:相当于服务端口(对及集群内客户访问) targetPort: 相当于pods端口 nodePort: 宿主机端口(也是服务端口,只不过是对集群外客户访问)