k8s二进制部署(三)

举报
ming-1 发表于 2021/01/28 22:28:23 2021/01/28
【摘要】 安装Master节点组件##创建所需目录mkdir -p /opt/kubernetes_master/{bin,cfg,ssl,log}##下载解压kubernetes文件https://github.com/kubernetes/kubernetes/blob/master/CHANGELOG/CHANGELOG-1.18.mdtar -zxvf kubernetes-server-li...

安装Master节点组件

##创建所需目录

mkdir -p /opt/kubernetes_master/{bin,cfg,ssl,log}

##下载解压kubernetes文件

https://github.com/kubernetes/kubernetes/blob/master/CHANGELOG/CHANGELOG-1.18.md

tar -zxvf kubernetes-server-linux-amd64.tar.gz

##移动文件至kubernetes_master目录

cd kubernetes/server/bin/

cp kube-apiserver kube-scheduler kube-controller-manager /opt/kubernetes_master/bin

##签发证书

cd /opt/k8s/k8s-cert

cat > ca-config.json << EOF
{
  "signing": {
    "default": {
      "expiry": "87600h"
    },
    "profiles": {
      "kubernetes": {
         "expiry": "87600h",
         "usages": [
            "signing",
            "key encipherment",
            "server auth",
            "client auth"
        ]
      }
    }
  }
}
EOF
cat > ca-csr.json << EOF
{
    "CN": "kubernetes",
    "key": {
        "algo": "rsa",
        "size": 2048
    },
    "names": [
        {
            "C": "CN",
            "L": "Beijing",
            "ST": "Beijing",
            "O": "k8s",
            "OU": "System"
        }
    ]
}
EOF

##通过gencert -initca来初始化,然后使用cfssljson命令保存

cfssl gencert -initca ca-csr.json | cfssljson -bare ca -

##生成apiserver证书请求文件(ip地址为可以多设置几个以备扩展使用)

cat > apiserver-csr.json << EOF
{
    "CN": "kubernetes",
    "hosts": [
            "10.0.0.1",
      "127.0.0.1",
      "10.107.141.50",
      "10.107.141.53",
      "10.107.141.54",
      "10.107.141.55",
      "kubernetes",
      "kubernetes.default",
      "kubernetes.default.svc",
      "kubernetes.default.svc.cluster",
      "kubernetes.default.svc.cluster.local"
    ],
    "key": {
        "algo": "rsa",
        "size": 2048
    },
    "names": [
        {
            "C": "CN",
            "L": "BeiJing",
            "ST": "BeiJing",
            "O": "k8s",
            "OU": "System"
        }
    ]
}
EOF

##生成apiserver证书

cfssl gencert -ca=ca.pem -ca-key=ca-key.pem -config=ca-config.json -profile=kubernetes apiserver-csr.json | cfssljson -bare apiserver

##移动文件至工作目录

cp ca.pem apiserver.pem apiserver-key.pem ca-key.pem /opt/kubernetes_master/ssl/

##生成kube-apiserver.conf,kube-controller-manager.conf,kube-scheduler.conf配置文件

cd /opt/kubernetes_master/cfg/

##生成对应的systemd文件

cat > /usr/lib/systemd/system/kube-apiserver.service << EOF
[Unit]
Description=Kubernetes API Server
Documentation=https://github.com/kubernetes/kubernetes
[Service]
EnvironmentFile=/opt/kubernetes_master/cfg/kube-apiserver.conf
ExecStart=/opt/kubernetes_master/bin/kube-apiserver \$KUBE_APISERVER_OPTS
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF

cat > /usr/lib/systemd/system/kube-controller-manager.service << EOF
[Unit]
Description=Kubernetes Controller Manager
Documentation=https://github.com/kubernetes/kubernetes
[Service]
EnvironmentFile=/opt/kubernetes_master/cfg/kube-controller-manager.conf
ExecStart=/opt/kubernetes_master/bin/kube-controller-manager \$KUBE_CONTROLLER_MANAGER_OPTS
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF

cat > /usr/lib/systemd/system/kube-scheduler.service << EOF
[Unit]
Description=Kubernetes Scheduler
Documentation=https://github.com/kubernetes/kubernetes
[Service]
EnvironmentFile=/opt/kubernetes_master/cfg/kube-scheduler.conf
ExecStart=/opt/kubernetes_master/bin/kube-scheduler \$KUBE_SCHEDULER_OPTS
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。