本文内容
主要对K8s 的安装做记录安装前,请准备两台以上的linux服务器,且都已经安装好docker了安装大致步骤
安装 kubectl安装 minikube启动可视化界面 dashboard
安装 kubectl
下载 kubectl
下载最新的稳定版本 curl -LO https://storage.googleapis.com/kubernetes-release/release/`curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt`/bin/linux/amd64/kubectl
常用版本下载 curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.18.0/bin/linux/amd64/kubectl
添加执行权限
chmod +x ./kubectl
使其在全局都可执行
sudo mv ./kubectl /usr/local/bin/kubectl
安装 minikube
下载minikubecurl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 && chmod +x minikube
使其在全局都可执行mv minikube /usr/local/bin/
minikube 不可以使用 root 用户执行
添加用户$ useradd test
$ echo 1234 | passwd test --stdin
$ visudo # 将用户添加到 sudo 文件中,就可以使用 sudo 进行授权执行高权限命令了
# 改成下面这样
root ALL=(ALL) ALL
test ALL=(ALL) ALL
将用户 添加到 root组$ usermod -aG root test
将用户添加到 docker组$ sudo usermod -aG docker test && newgrp docker
启动 minikube
进入 test 用户$ su test
使用国内的docker镜像源启动 minikube$ minikube start --image-mirror-country='cn' --registry-mirror=https://registry.docker-cn.com --driver=docker
查看是否安装成功$ minikube status
type: Control Pline
host: Running
kubelet: Running
kubeconfig: Configured
查看k8s节点$ kubectl get nodes
NAME STATUS ROLES AGE VERSION
minikube Ready master 73m v1.18.3
创建部署文件,deployment.yamlapiVersion: apps/v1
kind: Deployment
metadata:
name: hello-world
spec:
selector:
matchLabels:
run: load-balancer-example
replicas: 2
template:
metadata:
labels:
run: load-balancer-example
spec:
containers:
- name: hello-world
image: registry.cn-hangzhou.aliyuncs.com/aliyun_google/google-sample-node-hello:1.0
ports:
- containerPort: 8080
protocol: TCP
在该文件的目录下执行命令,部署hello-world$ kubectl apply -f deployment.yaml
暴露端口$ kubectl expose deployment hello-world --type=NodePort --name=node-service
查看访问的地址$ minikube service list
或者
$ minikube service node-service --url
出现 Hello Kubernetes!
启动 dashboard
minikube dashboard
报错如下
Failed to open connection to "session" message bus: Unable to autolaunch a dbus-daemon without a $DISPLAY for X11
Running without a11y support!
Error: no DISPLAY environment variable specified
因为linux除ubuntu外没有浏览器,所以需要加上 --url即 minikube dashboard --url
默认地址只能是 本机地址,暴露地址 1.1.1.1 是服务器的地址 8888 是访问端口
nohup kubectl proxy --port=8888 --address='1.1.1.1' --accept-hosts='^1.1.1.1$' >/dev/null 2>&1&
参考https://www.jianshu.com/p/ef020fa8ca97
界面展示