# K8s安装registry仓库

### 编辑Docker配置文件（所有节点执行）

```bash
sed -i "s#OPTIONS='--selinux-enabled --log-driver=journald --signature-verification=false'#OPTIONS='--selinux-enabled --log-driver=journald --signature-verification=false --registry-mirror=https://registry.docker-cn.com --insecure-registry=10.0.0.10:5000'#g" /etc/sysconfig/docker

systemctl restart docker

```

### 仓库节点执行

```bash
#运行registry仓库
docker pull registry:2.7.1
docker run -d -p 5000:5000 --restart=always --name registry -v /opt/myregistry:/var/lib/registry docker.io/registry:2.7.1

#测试仓库是否可用，需关闭selinux，否则会一直重试同时提示500错误
docker pull nginx:1.19.1
docker tag docker.io/nginx:1.19.1 10.0.0.10:5000/nginx:1.19.1
docker push 10.0.0.10:5000/nginx:1.19.1

```

{% hint style="danger" %}
若遇到错误：

Get <https://10.0.0.10:5000/v1/\\_ping>: http: server gave HTTP response to HTTPS client，则增加如下配置，然后重启docker

vim /etc/docker/daemon.json

{

"insecure-registries":\["10.0.0.10:5000"]

}
{% endhint %}

#### 查看镜像

```bash
# 查看镜像列表，浏览器访问
http://10.0.0.10:5000/v2/_catalog

# 查看镜像版本，浏览器访问（此处为查看nginx镜像的版本，查看其他镜像换掉nginx字符串即可）
http://10.0.0.10:5000/v2/nginx/tags/list
```

### 使用K8s运行一个Pod（主节点）

```yaml
mkdir /root/k8s/pod -p
cd /root/k8s/pod/

cat > k8s_pod.yaml << EOF
apiVersion: v1
kind: Pod
metadata:
  name: test
  labels:
    app: web
spec:
  containers:
    - name: nginx
      image: 10.0.0.10:5000/nginx:1.19.1
      ports:
        - containerPort: 80
    - name: busybox
      image: 10.0.0.10:5000/busybox:latest
      command: ["sleep", "1000"]
EOF

kubectl create -f k8s_pod.yaml
kubectl get pod
kubectl describe pod test

```

#### k8s资源常见操作

```bash
kubectl create -f xxx.yaml

kubectl get pod

kubectl describe pod xxxx

kubectl delete pod xxx
kubectl delete -f xxx.yaml
kubectl delete pod --all
kubectl delete xx --all

kubectl edit pod xxx
```
