# 1. k8s认证
## 1.2 两种账户信息
1. user账户
2. pod访问apiServer的一种账户(service account)
`kubectl config view`对应配置文件/root/.kube/config(认证信息)
```
apiVersion: v1
clusters:
- cluster:
certificate-authority-data: DATA+OMITTED
server: https://192.168.56.10:6443
name: kubernetes
contexts:
- context:
cluster: kubernetes
user: kubernetes-admin
name: kubernetes-admin@kubernetes
current-context: kubernetes-admin@kubernetes
kind: Config
preferences: {}
users:
- name: kubernetes-admin
user:
client-certificate-data: REDACTED
client-key-data: REDACTED
```
有四种实体,users对象列表,clusters集群列表,contexts用户与集群对应关系,current-context用来指定当前连接那个集群
# 2. 创建serviceAccount
**1. 使用k8是证书签名serviceAccount证书**
```
# private key
openssl genrsa -out tuna.key 1024
# private Ca
openssl req -new -key tuna.key -out tuna.csr -subj "/CN=tuna"
# sign CA
openssl x509 -req -in tuna.csr -CA /etc/kubernetes/pki/ca.crt -CAkey /etc/kubernetes/pki/ca.key -CAcreateserial -out tuna.crt -days 365
```
**2. config加入用户tuna**
```
[root@master serviceAccount]# kubectl config set-credentials tuna --client-certificate=./tuna.crt --embed-certs=true --client-key=./tuna.key
User "tuna" set.
[root@master serviceAccount]# kubectl config view
apiVersion: v1
clusters:
...
- name: tuna
user:
client-certificate-data: REDACTED
client-key-data: REDACTED
```
**3. 操作context将用户与集群绑定**
```
[root@master serviceAccount]# kubectl config set-context tuna@kubernates --cluster=kubernates --user=tuna
Context "tuna@kubernates" created.
[root@master serviceAccount]# kubectl config view
apiVersion: v1
clusters:
- cluster:
certificate-authority-data: DATA+OMITTED
server: https://192.168.56.10:6443
name: kubernetes
contexts:
- context:
cluster: kubernetes
user: kubernetes-admin
name: kubernetes-admin@kubernetes
- context:
cluster: kubernates
user: tuna
name: tuna@kubernates
```
**4. 使用tuna操作k8s**
> 当前用户切换到tuna
```
[root@master serviceAccount]# kubectl config use-context tuna@kubernates
Switched to context "tuna@kubernates".
```
```
[root@master serviceAccount]# kubectl get pods
error: no configuration has been provided, try setting KUBERNETES_MASTER environment variable
```
- docker
- docker安装
- 数据持久化
- 镜像管理
- Dockerfile
- 镜像的分层
- add copy
- 构建实例
- 镜像的导入导出
- 清理构建空间
- 配置阿里云加速器
- docker网络模型
- 本地仓库
- registry
- harbor
- IDEA部署docker
- 软件安装
- 安装es
- 安装MongoDB
- 安装rabbitmq
- 安装redis
- 安装nacos
- 安装mysql
- Minio
- 镜像中心
- kubernetes
- 1. 安装k8s
- 2.主要组件
- 3.污点
- 4.pod
- 5.控制器
- 6.网络
- 7.探针
- 8.安装Dashbord
- 9.secret
- 9.serviceAccount
- 10.service
- 资源清单
- kube-proxy
- flannel源文件
- 服务升级
- 笔记
- 镜像