Kubernetes -- Server 部署
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Kubernetes -- Server 部署相关的知识,希望对你有一定的参考价值。
1. Node 节点配置文件
1.1 下载相关的软件
wget https://dl.k8s.io/v1.9.6/kubernetes-server-linux-amd64.tar.gz
wget https://dl.k8s.io/v1.13.1/kubernetes-client-linux-amd64.tar.gz
上面的 client 包里只有一个 kubectl 的脚本,这个脚本在 kubernetes-server-linux-amd64.tar.gz 也有。
1.2. 创建一个文件 /opt/k8s/cfg/gen-cfg.sh , 并增加执行权限,文件内容如下:
#! /bin/bash # create TLS Bootstrapping Token export BOOTSTRAP_TOKEN=$(head -c 16 /dev/urandom | od -An -t x | tr -d ) cat > token.csv <10001,"system:kubelet-bootstrap" EOF #---------------- #创建 kubelet bootstrapping 配置文件 export KUBE_APISERVER="https://192.168.137.81:6443" # 设置 cluster 参数 kubectl config set-cluster kubernetes \\ --certificate-authority=/opt/k8s/ssl/ca.pem \\ --embed-certs=true \\ --server=$KUBE_APISERVER \\ --kubeconfig=bootstrap.kubeconfig # 设置客户端认证参数 kubectl config set-credentials kubelet-bootstrap \\ --token=$BOOTSTRAP_TOKEN \\ --kubeconfig=bootstrap.kubeconfig
#设置上下文 kubectl config set-context default \\ --cluster=kubernetes \\ --user=kubelet-bootstrap \\ --kubeconfig=bootstrap.kubeconfig kubectl config use-context default --kubeconfig=bootstrap.kubeconfig #------------- #创建 kube-proxy 配置文件 kubectl config set-cluster kubernetes \\ --certificate-authority=/opt/k8s/ssl/ca.pem \\ --embed-certs=true \\ --server=$KUBE_APISERVER \\ --kubeconfig=kube-proxy.kubeconfig kubectl config set-credentials kube-proxy \\ --client-certificate=/opt/k8s/ssl/kube-proxy.pem \\ --client-key=/opt/k8s/ssl/kube-proxy-key.pem \\ --embed-certs=true \\ --kubeconfig=kube-proxy.kubeconfig kubectl config set-context default \\ --cluster=kubernetes \\ --user=kube-proxy \\ --kubeconfig=kube-proxy.kubeconfig kubectl config use-context default --kubeconfig=kube-proxy.kubeconfig
1.3. 运行此脚本,会生成两个文件, 一个文件是 bootstrap.kubeconfig, 另一个是 kube-proxy.kubeconfig
2. Master
2.1 创建 apiserver 的配置文件 vim /opt/k8s/kube-apiserver.conf,内容如下:
KUBE_APISERVER_OPTS="--logtostderr=true \\ --v=4 \\--etcd-servers=$ETCD_SERVERS \\ --insecure-bind-address=127.0.0.1 \\--bind-address=$MASTER_ADDRESS \\ --insecure-port=8080 \\--secure-port=6443 \\--advertise-address=$MASTER_ADDRESS \\ --allow-privileged=true \\--service-cluster-ip-range=10.10.10.0/24 \\--admission-control=NamespaceLifecycle,LimitRanger,SecurityContextDeny,ServiceAccount,ResourceQuota,NodeRestriction \\ --authorization-mode=RBAC,Node \\ --kubelet-https=true \\--enable-bootstrap-token-auth \\ --token-auth-file=/opt/k8s/cfg/token.csv \\--service-node-port-range=30000-50000 \\--tls-cert-file=/opt/k8s/ssl/server.pem \\--tls-private-key-file=/opt/k8s/ssl/server-key.pem \\--client-ca-file=/opt/k8s/ssl/ca.pem \\--service-account-key-file=/opt/k8s/ssl/ca-key.pem \\--etcd-cafile=/opt/k8s/ssl/ca.pem \\ --etcd-certfile=/opt/k8s/ssl/server.pem \\ --etcd-keyfile=/opt/k8s/ssl/server-key.pem"
2.2 创建 service: vim /usr/lib/systemd/system/kube-apiserver.service
[Unit]Description=Kubernetes API Server Documentation=https://github.com/kubernetes/kubernetes [Service] EnvironmentFile=-/opt/k8s/cfg/kube-apiserver.conf ExecStart=/opt/k8s/bin/kube-apiserver \\$KUBE_APISERVER_OPTS Restart=on-failure [Install] WantedBy=multi-user.target
2.3 启动 service 及查看状态
systemctl daemon-reloadsystemctl enable kube-apiserver systemctl restart kube-apiserver
systemctl status kube-apiserver
3. controller-manager
3.1 创建文件 vim /opt/k8s/cfg/kube-contoller-manager.conf,内容如下:
KUBE_CONTROLLER_MANAGER_OPTS="--logtostderr=true \\ --v=4 \\--master=127.0.0.1:8080 \\--leader-elect=true \\--address=127.0.0.1 \\--service-cluster-ip-range=10.10.10.0/24 \\--cluster-name=kubernetes \\ --cluster-signing-cert-file=/opt/k8s/ssl/ca.pem \\--cluster-signing-key-file=/opt/k8s/ssl/ca-key.pem \\--root-ca-file=/opt/k8s/ssl/ca.pem \\--service-account-private-key-file=/opt/k8s/ssl/ca-key.pem"
3.2 创建文件 vim /usr/lib/systemd/system/kube-controller-manager.service,内容如下:
[Unit]Description=Kubernetes Controller Manager Documentation=https://github.com/kubernetes/kubernetes [Service] EnvironmentFile=-/opt/k8s/cfg/kube-controller-manager.conf ExecStart=/opt/k8s/bin/kube-controller-manager $KUBE_CONTROLLER_MANAGER_OPTS Restart=on-failure [Install] WantedBy=multi-user.target
3.3 启动 service 及查看状态
systemctl daemon-reloadsystemctl enable controller-manager systemctl restart controller-manager systemctl status controller-manager
4. scheduler
4.1 创建文件 vim /opt/k8s/cfg/kube-scheduler.conf,内容如下:
KUBE_SCHEDULER_OPTS="--logtostderr=true --v=4 --master=127.0.0.1:8080 --leader-elect"
4.2 创建文件 vim /usr/lib/systemd/system/kube-scheduler.service,内容如下:
[Unit]Description=Kubernetes Scheduler Documentation=https://github.com/kubernetes/kubernetes [Service] EnvironmentFile=-/opt/k8s/cfg/kube-scheduler.conf ExecStart=/opt/k8s/bin/kube-scheduler $KUBE_SCHEDULER_OPTS Restart=on-failure [Install] WantedBy=multi-user.target
4.3 启动 service 及查看状态
systemctl daemon-reloadsystemctl enable kube-scheduler systemctl restart kube-scheduler systemctl status kube-scheduler
以上是关于Kubernetes -- Server 部署的主要内容,如果未能解决你的问题,请参考以下文章
Kubernetes1.15.2集群部署并部署Metrics Server插件
Kubernetes深入学习之二:编译和部署镜像(api-server)
kubernetes 1.14安装部署metrics-server插件