k8s二进制部署(五)
【摘要】 ##切回node节点(在node节点都需要执行,更改ip地址即可)##创建kubelet.conf和kut-config.ymlcat > /opt/kubernetes_node/cfg/kubelet-config.yml << EOFkind: KubeletConfigurationapiVersion: kubelet.config.k8s.io/v1beta1address: 1...
##切回node节点(在node节点都需要执行,更改ip地址即可)
##创建kubelet.conf和kut-config.yml
cat > /opt/kubernetes_node/cfg/kubelet-config.yml << EOF
kind: KubeletConfiguration
apiVersion: kubelet.config.k8s.io/v1beta1
address: 10.107.141.51
port: 10250
readOnlyPort: 10255
cgroupDriver: cgroupfs
clusterDNS:
- 10.0.0.2
clusterDomain: cluster.local
failSwapOn: false
authentication:
anonymous:
enabled: false
webhook:
cacheTTL: 2m0s
enabled: true
x509:
clientCAFile: /opt/kubernetes_node/ssl/ca.pem
authorization:
mode: Webhook
webhook:
cacheAuthorizedTTL: 5m0s
cacheUnauthorizedTTL: 30s
evictionHard:
imagefs.available: 15%
memory.available: 100Mi
nodefs.available: 10%
nodefs.inodesFree: 5%
maxOpenFiles: 1000000
maxPods: 110
EOF
cat > /opt/kubernetes_node/cfg/kubelet.conf << EOF
KUBELET_OPTS="--logtostderr=false \\
--v=2 \\
--log-dir=/opt/kubernetes_node/log \\
--hostname-override=10.107.141.51 \\
--kubeconfig=/opt/kubernetes_node/cfg/kubelet.kubeconfig \\
--bootstrap-kubeconfig=/opt/kubernetes_node/cfg/bootstrap.kubeconfig \\
--config=/opt/kubernetes_node/cfg/kubelet-config.yml \\
--cert-dir=/opt/kubernetes_node/ssl \\
--pod-infra-container-image=registry.cn-hangzhou.aliyuncs.com/google-containers/pause-amd64:3.0"
EOF
##创建kubelet的systemd文件
cat > /usr/lib/systemd/system/kubelet.service << EOF
[Unit]
Description=Kubernetes Kubelet
After=docker.service
[Service]
EnvironmentFile=/opt/kubernetes_node/cfg/kubelet.conf
ExecStart=/opt/kubernetes_node/bin/kubelet \$KUBELET_OPTS
Restart=on-failure
LimitNOFILE=65536
[Install]
WantedBy=multi-user.target
EOF
##将master节点的ca.pem证书传输至ssl目录下
scp ca.pem root@10.107.141.51:/opt/kubernetes_node/ssl/
scp ca.pem root@10.107.141.52:/opt/kubernetes_node/ssl/
##启动kubelet
systemctl start kubelet
systemctl enable kubelet
##到master节点允许node节点的加入
kubectl get csr
kubectl certificate approve 查询到的请求名称
kubelet get node
##配置kube-proxy文件
cat > /usr/lib/systemd/system/kube-proxy.service << EOF
[Unit]
Description=Kubernetes Proxy
After=network.target
[Service]
EnvironmentFile=/opt/kubernetes_node/cfg/kube-proxy.conf
ExecStart=/opt/kubernetes_node/bin/kube-proxy \$KUBE_PROXY_OPTS
Restart=on-failure
LimitNOFILE=65536
[Install]
WantedBy=multi-user.target
EOF
cat > /opt/kubernetes_node/cfg/kube-proxy.conf << EOF
KUBE_PROXY_OPTS="--logtostderr=false \\
--v=2 \\
--log-dir=/opt/kubernetes_node/logs \\
--hostname-override=10.107.141.51 \\
--cluster-cidr=10.0.0.0/24 \\
--proxy-mode=ipvs \\
--kubeconfig=/opt/kubernetes_node/cfg/kube-proxy.kubeconfig"
EOF
##启动kube-proxy
systemctl start kube-proxy
测试集群
启动一个简单的nginx-deployment和nginx-service
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx
spec:
selector:
matchLabels:
app: nginx
replicas: 1
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx
ports:
- containerPort: 80
apiVersion: apps/v1
kind: Service
metadata:
name: nginx
spec:
type: NodePort
ports:
- port: 8000
targetPort: 80
nodePort: 31111
selector:
app: nginx
##运行yaml文件
docker apply -f nginx-deployment
docker apply -f nginx-svc
##查看svc启动情况
kubelet get svc
##尝试访问服务
curl nodeip:31111
至此k8s二进制部署1master+2node节点完成部署
【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)