1
idblife 2021-11-24 10:10:13 +08:00 via iPhone
用什么方案搭建的
|
3
lovewell OP 这是我的 apiserver 启动配置:
KUBE_APISERVER_ARGS=' --api-audiences=https://kubernetes.default.svc.cluster.local --runtime-config=api/all=true --apiserver-count=3 --allow-privileged=true --advertise-address=192.168.62.131 --bind-address=0.0.0.0 --secure-port=6443 --storage-backend=etcd3 --etcd-cafile=/etc/etcd/pki/etcd-ca.pem --etcd-certfile=/etc/kubernetes/kube-apiserver/pki/kube-apiserver-client-etcd.pem --etcd-keyfile=/etc/kubernetes/kube-apiserver/pki/kube-apiserver-client-etcd-key.pem --etcd-servers=https://192.168.62.131:2379,https://192.168.62.132:2379,https://192.168.62.133:2379 --kubelet-certificate-authority=/etc/kubernetes/pki/kubernetes-ca.pem --kubelet-client-certificate=/etc/kubernetes/kube-apiserver/pki/kube-apiserver-client-kubelet.pem --kubelet-client-key=/etc/kubernetes/kube-apiserver/pki/kube-apiserver-client-kubelet-key.pem --kubelet-preferred-address-types=InternalIP,InternalDNS,ExternalIP,ExternalDNS,Hostname --kubelet-timeout=10s --service-cluster-ip-range=10.22.88.0/22 --service-node-port-range=30000-32767 --service-account-key-file=/etc/kubernetes/kube-apiserver/pki/sa-pub.pem --service-account-issuer=https://kubernetes.default.svc.cluster.local --service-account-signing-key-file=/etc/kubernetes/kube-apiserver/pki/sa-signing-key.pem --enable-bootstrap-token-auth=true --anonymous-auth=false --authorization-mode=RBAC,Node --client-ca-file=/etc/kubernetes/pki/kubernetes-ca.pem --cert-dir=/etc/kubernetes/kube-apiserver/pki --tls-cert-file=/etc/kubernetes/kube-apiserver/pki/kube-apiserver.pem --tls-private-key-file=/etc/kubernetes/kube-apiserver/pki/kube-apiserver-key.pem --event-ttl=168h --audit-log-maxage=15 --audit-log-maxbackup=3 --audit-log-maxsize=100 --audit-log-truncate-enabled --audit-log-path=/var/log/kubernetes/kube-apiserver/audit.log --audit-policy-file=/etc/kubernetes/kube-apiserver/audit-policy.yaml --requestheader-allowed-names=aggregator-proxy-client --requestheader-extra-headers-prefix=X-Remote-Extra- --requestheader-group-headers=X-Remote-Group --requestheader-username-headers=X-Remote-User --requestheader-client-ca-file=/etc/kubernetes/pki/aggregation-ca.pem --proxy-client-cert-file=/etc/kubernetes/kube-apiserver/pki/aggregator-proxy-client.pem --proxy-client-key-file=/etc/kubernetes/kube-apiserver/pki/aggregator-proxy-client-key.pem --enable-aggregator-routing=true --profiling --default-not-ready-toleration-seconds=360 --default-unreachable-toleration-seconds=360 --max-mutating-requests-inflight=2000 --max-requests-inflight=4000 --default-watch-cache-size=200 --delete-collection-workers=2 --logtostderr=false --logging-format=text --log-dir=/var/log/kubernetes/kube-apiserver --v=2 ' 这是我的 kube-controller-manager 配置: KUBE_CONTROLLER_MANAGER_ARGS=' --cluster-name=kubernetes --profiling --kubeconfig=/etc/kubernetes/kube-controller-manager/kube-controller-manager-kubeconfig.yaml --authentication-kubeconfig=/etc/kubernetes/kube-controller-manager/kube-controller-manager-kubeconfig.yaml --authorization-kubeconfig=/etc/kubernetes/kube-controller-manager/kube-controller-manager-kubeconfig.yaml --controllers=*,bootstrapsigner,tokencleaner --bind-address=0.0.0.0 --service-cluster-ip-range=10.22.88.0/22 --kube-api-qps=1000 --kube-api-burst=2000 --use-service-account-credentials=true --concurrent-service-syncs=2 --root-ca-file=/etc/kubernetes/pki/kubernetes-ca.pem --service-account-private-key-file=/etc/kubernetes/kube-controller-manager/pki/sa-key.pem --allocate-node-cidrs=true --cluster-cidr=172.16.0.0/12 --node-cidr-mask-size=24 --cert-dir=/etc/kubernetes/kube-controller-manager/pki --tls-cert-file=/etc/kubernetes/kube-controller-manager/pki/kube-controller-manager.pem --tls-private-key-file=/etc/kubernetes/kube-controller-manager/pki/kube-controller-manager-key.pem --client-ca-file=/etc/kubernetes/pki/kubernetes-ca.pem --cluster-signing-cert-file=/etc/kubernetes/pki/kubernetes-ca.pem --cluster-signing-key-file=/etc/kubernetes/pki/kubernetes-ca-key.pem --requestheader-allowed-names=aggregator-proxy-client --requestheader-extra-headers-prefix=X-Remote-Extra- --requestheader-group-headers=X-Remote-Group --requestheader-username-headers=X-Remote-User --requestheader-client-ca-file=/etc/kubernetes/pki/aggregation-ca.pem --logtostderr=false --logging-format=text --log-dir=/var/log/kubernetes/kube-controller-manager --v=2 ' 感觉没问题,实际不行。 |
4
hwdef 2021-11-24 10:16:52 +08:00
用 kubeadm 吧。
|
5
hwdef 2021-11-24 10:17:17 +08:00
或者 kind minikube
|
6
swulling 2021-11-24 10:20:36 +08:00
用 K3s ,你这个 Unauthorized 应该是权限和证书出问题了。
|
7
defunct9 2021-11-24 10:21:01 +08:00
kube-controller-manager 里没有配置 node ip range 吧
|
8
lovewell OP 过了认证,但是没被授权。我试过吧 kubeconfig 换成 CN:admin O:system:masters 也不行。。所以我就想是他请求 ip 份配的时候到底是用那个角色。。
|
10
hwdef 2021-11-24 10:40:50 +08:00
kubeadm 已经是官方指定的,可以用在生产力的,k8s 环境搭建工具了。。。。没必要把时间浪费在搭建环境上。
|
11
amrom 2021-11-24 10:51:13 +08:00
签发 kube-controller-manager-kubeconfig.yaml 的证书权限不足,重新签发一个
|
12
goushenggege 2021-11-24 10:53:09 +08:00
新手学习还是 kubeadm 安装吧,二进制容易劝退
|
13
betainCao 2021-11-24 10:53:24 +08:00
|
15
suifengdang666 2021-11-24 11:00:18 +08:00
建议还是 kubeadm 搭建,二进制搭建太费时间费精力,还一堆问题
|
16
yibo2018 2021-11-24 11:16:13 +08:00
哎,很多时候我都在想,为啥已经很成熟的东西都没有完全傻瓜式的方式,或者完美的文档,总是有坑。尤其是在配置环境的时候,时间都耗在配置环境是真难受。 就很羡慕解决问题能力强的人吗,之前的 leader 就很变态,都是靠自己的思路去解决的,google 都很少用
|
17
lovewell OP @amrom 大佬,我在 3 个节点单节中关闭 2 个,然后用 kubectl 的 admin 证书替换掉 kube-controller-manager 的 kubeconfig,auth/z-kubeconfig 也是失败的。下面是我的生成 kube-controller-manager-kubeconfig.yaml 的过程。
=== 这个是 csr: { "CN": "system:kube-controller-manager", "hosts": [ "192.168.62.131", "192.168.62.132", "192.168.62.133", "127.0.0.1", "localhost" ], "key": { "algo": "rsa", "size": 2048 }, "names": [ { "C": "CN", "ST": "Guangdong", "L": "Dongguan", "O": "system:kube-controller-manager", "OU": "Kubernetes" } ] } ansible 对应的脚本: - name: kube-controller-manager-csr.json ansible.builtin.shell: cmd: >- cfssl gencert -ca {{ control_node_temp_dirs.temp_certs_dir }}/kubernetes-ca.pem -ca-key {{ control_node_temp_dirs.temp_certs_dir }}/kubernetes-ca-key.pem -config {{ role_path }}/ca-config.json -profile peer {{ control_node_temp_dirs.temp_csrs_dir }}/kube-controller-manager-csr.json | cfssljson -bare {{ control_node_temp_dirs.temp_certs_dir }}/kube-controller-manager - name: set-cluster kube-controller-manager-kubeconfig.yaml ansible.builtin.shell: cmd: >- kubectl config set-cluster {{ k8s.cluster_name }} --certificate-authority={{ control_node_temp_dirs.temp_certs_dir }}/kubernetes-ca.pem --embed-certs=true --server=https://127.0.0.1:6443 --kubeconfig={{ control_node_temp_dirs.temp_kubeconfigs_dir }}/kube-controller-manager-kubeconfig.yaml - name: set-credentials kube-controller-manager-kubeconfig.yaml ansible.builtin.shell: cmd: >- kubectl config set-credentials system:kube-controller-manager --client-certificate={{ control_node_temp_dirs.temp_certs_dir }}/kube-controller-manager.pem --client-key={{ control_node_temp_dirs.temp_certs_dir }}/kube-controller-manager-key.pem --embed-certs=true --kubeconfig={{ control_node_temp_dirs.temp_kubeconfigs_dir }}/kube-controller-manager-kubeconfig.yaml - name: set-context kube-controller-manager-kubeconfig.yaml ansible.builtin.shell: cmd: >- kubectl config set-context default --cluster={{ k8s.cluster_name }} --user=system:kube-controller-manager --kubeconfig={{ control_node_temp_dirs.temp_kubeconfigs_dir }}/kube-controller-manager-kubeconfig.yaml - name: kubeconfig use-context kube-controller-manager ansible.builtin.shell: cmd: kubectl config use-context default --kubeconfig={{ control_node_temp_dirs.temp_kubeconfigs_dir }}/kube-controller-manager-kubeconfig.yaml |
19
locoz 2021-11-24 12:03:35 +08:00
建议直接 kubeadm ,官方推荐方案,坑少。
另外,刚接触不要直接搞太新的版本,往后退 1-2 个版本会好点,主要有些应用不一定兼容新版本的 API 。 |
20
idblife 2021-11-24 12:09:20 +08:00 via iPhone
kubeadm 吧
按照官方教程一次成功 |
22
amrom 2021-11-24 13:40:40 +08:00
@lovewell 试试加个 rolebinding ,kubectl create rolebinding xx-binding --clusterrole=admin --user=system:kube-controller-manager
|
23
eaglewangl37670 2021-11-24 15:55:50 +08:00
我之前遇到过是用楼上的方案解决的,不知道二进制这种有没有用
|
25
Reficul 2021-11-24 18:05:08 +08:00
clusterrolebinding system:kube-controller-manager 感觉是 API 启动的时候写的,可以看看代码。
|
26
offswitch 2021-11-25 22:27:46 +08:00
你的这些配置参数,都可以通过 KubeletConfiguration 、KubeProxyConfiguration 、ClusterConfiguration 、InitConfiguration 、JoinConfiguration 来配置,可以看看这个 https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/control-plane-flags/
|
27
lework1234 2021-12-13 10:32:52 +08:00
github.com/lework/kainstall 一键安装。可以看看里面的 shell 脚本。
|