在上一篇部署好k8s之后,准备验证k8s的一些功能
1 测试 Pod 网络连通性
# 创建一个测试 Pod
kubectl run test-pod --image=busybox --command -- sleep 3600
# 使用国内的源
kubectl run test-pod --image=registry.cn-hangzhou.aliyuncs.com/google_containers/busybox:latest --command -- sleep 3600
# 进入 Pod 测试 DNS 和网络
kubectl exec -it test-pod -- ping -c 2 www.baidu.com
kubectl exec -it test-pod -- nslookup kubernetes.default
2 查看所有的镜像
# 列出所有镜像(类似 docker images)
sudo crictl images
3 命名空间的使用
kubectl create namespace <namespace-name>
3.1 通过 YAML 文件定义
创建一个 YAML 文件(如 namespace-dev.yaml)
apiVersion: v1 kind: Namespace metadata: name: dev labels: name: dev
使用 kubectl apply 命令创建命名空间
kubectl apply -f namespace-dev.yaml
4 pod的使用
apiVersion: v1
kind: Pod
metadata:
name: istack-nginx-pod
spec:
containers:
- name: nginx
image: docker.io/library/nginx:latest
imagePullPolicy: Never # 关键:只用本地
restartPolicy: Never
启动
kubectl apply -f nginx-pod.yaml
问题
拉取镜像失败
hw@host2:~/istack$ sudo crictl pull registry.cn-hangzhou.aliyuncs.com/library/nginx:latest
E1114 21:12:49.488834 24944 remote_image.go:167] "PullImage from image service failed" err="rpc error: code = Unknown desc = failed to pull and unpack image \"registry.cn-hangzhou.aliyuncs.com/library/nginx:latest\": failed to resolve reference \"registry.cn-hangzhou.aliyuncs.com/library/nginx:latest\": pull access denied, repository does not exist or may require authorization: server message: insufficient_scope: authorization failed" image="registry.cn-hangzhou.aliyuncs.com/library/nginx:latest"
FATA[0000] pulling image: rpc error: code = Unknown desc = failed to pull and unpack image "registry.cn-hangzhou.aliyuncs.com/library/nginx:latest": failed to resolve reference "registry.cn-hangzhou.aliyuncs.com/library/nginx:latest": pull access denied, repository does not exist or may require authorization: server message: insufficient_scope: authorization failed
crictl 拉取镜像失败,k8s启动pod失败 使用docker拉取镜像的方式来解决 juejin.cn/post/757246…