手动安装K8s第五节:master节点kubectl命令部署
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了手动安装K8s第五节:master节点kubectl命令部署相关的知识,希望对你有一定的参考价值。
1、部署kubectl 命令行工具
准备二进制包
[[email protected] ~]# cd /usr/local/src/kubernetes/client/bin
[[email protected] bin]# cp kubectl /opt/kubernetes/bin/
2、创建 admin 证书签名请求
[[email protected] bin]# cd /usr/local/src/ssl/
[[email protected] ssl]# vim admin-csr.json
{
"CN": "admin",
"hosts": [],
"key": {
"algo": "rsa",
"size": 2048
},
"names": [
{
"C": "CN",
"ST": "BeiJing",
"L": "BeiJing",
"O": "system:masters",
"OU": "System"
}
]
}
3、生成 admin 证书和私钥:
[[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 admin-csr.json | cfssljson -bare admin
2018/06/12 20:13:11 [INFO] generate received request
2018/06/12 20:13:11 [INFO] received CSR
2018/06/12 20:13:11 [INFO] generating key: rsa-2048
2018/06/12 20:13:12 [INFO] encoded CSR
2018/06/12 20:13:12 [INFO] signed certificate with serial number 165814787638355531945310975608531058629796019352
2018/06/12 20:13:12 [WARNING] This certificate lacks a "hosts" field. This makes it unsuitable for
websites. For more information see the Baseline Requirements for the Issuance and Management
of Publicly-Trusted Certificates, v.1.1.6, from the CA/Browser Forum (https://cabforum.org);
specifically, section 10.2.3 ("Information Requirements").
[[email protected] ssl]# mv admin*.pem /opt/kubernetes/ssl/
4、设置集群参数
[[email protected] ~]# kubectl config set-cluster kubernetes
--certificate-authority=/opt/kubernetes/ssl/ca.pem
--embed-certs=true
--server=https://192.168.137.171:6443
Cluster "kubernetes" set.
5、设置客户端认证参数
[[email protected] ~]# kubectl config set-credentials admin
--client-certificate=/opt/kubernetes/ssl/admin.pem
--embed-certs=true
--client-key=/opt/kubernetes/ssl/admin-key.pem
User "admin" set.
6、 设置上下文参数
[[email protected] ~]# kubectl config set-context kubernetes
--cluster=kubernetes
--user=admin
Context "kubernetes" created.
7、 设置默认上下文
[[email protected] ~]# kubectl config use-context kubernetes
Switched to context "kubernetes".
8、 使用kubectl工具
[[email protected] ~]# kubectl get cs
NAME STATUS MESSAGE ERROR
scheduler Healthy ok
etcd-0 Healthy {"health": "true"}
controller-manager Healthy ok
etcd-1 Healthy {"health": "true"}
etcd-2 Healthy {"health": "true"}
[[email protected] ~]# cat .kube/config
apiVersion: v1
clusters:
- cluster:
certificate-authority-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUR2akNDQXFhZ0F3SUJBZ0lVSDVEQ05wSU5DNGVNckJCK2RLMXUrZC9uVnB3d0RRWUpLb1pJaHZjTkFRRUwKQlFBd1pURUxNQWtHQTFVRUJoTUNRMDR4RURBT0JnTlZCQWdUQjBKbGFVcHBibWN4RURBT0JnTlZCQWNUQjBKbAphVXBwYm1jeEREQUtCZ05WQkFvVEEyczRjekVQTUEwR0ExVUVDeE1HVTNsemRHVnRNUk13RVFZRFZRUURFd3ByCmRXSmxjbTVsZEdWek1CNFhEVEU0TURZeE1qQTVNVEV3TUZvWERUSXpNRFl4TVRBNU1URXdNRm93WlRFTE1Ba0cKQTFVRUJoTUNRMDR4RURBT0JnTlZCQWdUQjBKbGFVcHBibWN4RURBT0JnTlZCQWNUQjBKbGFVcHBibWN4RERBSwpCZ05WQkFvVEEyczRjekVQTUEwR0ExVUVDeE1HVTNsemRHVnRNUk13RVFZRFZRUURFd3ByZFdKbGNtNWxkR1Z6Ck1JSUJJakFOQmdrcWhraUc5dzBCQVFFRkFBT0NBUThBTUlJQkNnS0NBUUVBdkRXcTI0SG45dGFwZlVxY0labnoKRFNBWjFESCtMaW1tY3B0ektyeEpVYm9YS0tCWi9kTlhQUE1EL2NUZFgyUmVOVElVL2JJSnd2aURaT0M2UnFLYQoyVkZKZFEwMzNaajRYbFYvakVIaFFvVUZydy9McUdTRlZnUmsyc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6443
name: kubernetes
contexts: - context:
cluster: kubernetes
user: admin
name: kubernetes
current-context: kubernetes
kind: Config
preferences: {}
users: - name: admin
user:
client-certificate-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUQzVENDQXNXZ0F3SUJBZ0lVSFF0a2FXRVQ4SE9OaEFzbmxSRWtBU2JGdkpnd0RRWUpLb1pJaHZjTkFRRUwKQlFBd1pURUxNQWtHQTFVRUJoTUNRMDR4RURBT0JnTlZCQWdUQjBKbGFVcHBibWN4RURBT0JnTlZCQWNUQjBKbAphVXBwYm1jeEREQUtCZ05WQkFvVEEyczRjekVQTUEwR0ExVUVDeE1HVTNsemRHVnRNUk13RVFZRFZRUURFd3ByCmRXSmxjbTVsZEdWek1CNFhEVEU0TURZeE1qRXlNRGd3TUZvWERURTVNRFl4TWpFeU1EZ3dNRm93YXpFTE1Ba0cKQTFVRUJoTUNRMDR4RURBT0JnTlZCQWdUQjBKbGFVcHBibWN4RURBT0JnTlZCQWNUQjBKbGFVcHBibWN4RnpBVgpCZ05WQkFvVERuTjVjM1JsYlRwdFlYTjBaWEp6TVE4d0RRWURWUVFMRXdaVGVYTjBaVzB4RGpBTUJnTlZCQU1UCkJXRmtiV2x1TUlJQklqQU5CZ2txaGtpRzl3MEJBUUVGQUFPQ0FROEFNSUlCQ2dLQ0FRRUF4c0YvTkNBVDBvZGYKYk5xa05KRUIvRHgwcXk0NWt4a2RZcy9ka2xuNzI5WEdGU1Nnamp1UnNhbWsyeTNmdUdQY1M1UnFOVGZHRzd3MQpwUzdxU01FQm5PL0JQUkQxWndrMmoxMU9Gc3p0ejBlOTlpa0hjLzlYdmFUcFEyQWVRMjZ0TDkxbjllbkEzamRXCmt5YWk3MS92VjRyaitNcGRscmdRd25DVlozanVOZlR6VVJwN2NVVmFqYkdBYjJDNVJlWkxZSENab1lhc2tLSTcKUGh4Z1YxM0ZnbkVhU2dHUy9Ja2xza01adWYzT3lteVZ1TlZ3RExyTUVMNTdZeWtW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o=
[[email protected] ~]#
以上是关于手动安装K8s第五节:master节点kubectl命令部署的主要内容,如果未能解决你的问题,请参考以下文章
3-Kubernetes入门之CentOS上安装部署k8s集群