vim nginx.yaml
apiVersion: v1
kind: Pod
metadata:
name: nginx
labels:
app: web
spec:
containers:
- name: nginx
image: nginx:1.13
ports:
- containerPort: 80
创建的命令
需要apiserver中的serviceAccount去掉
[root@k8s-master k8s]# kubectl create -f nginx.yaml
pod “nginx” created
解析
指定apiVersion版本
kind Pod,Deployment service等等
元数据
metadata:
name: nginx labels: app web
详情spec,容器 名字 镜像 端口
containers:
- name: nginx
image: nginx:1.13
ports:
- containerPort
[root@k8s-master k8s]# kubectl get pods
NAME READY STATUS RESTARTS AGE
nginx 1/1 Running 0 5m
获取pod详情
[root@k8s-master k8s]# kubectl get pod nginx -o wide
NAME READY STATUS RESTARTS AGE IP NODE
nginx 1/1 Running 0 6m 172.16.25.2 k8s-node2
vim /etc/kubenetes/kubelet 修改如下内容
# pod infrastructure container
KUBELET_POD_INFRA_CONTAINER="--pod-infra-container-image=docker.io/tianyebj/pod-infrastructure:latest"
docker pull registry 拉去基础镜像
开启私有仓库
docker load -i registry.tar.gz
docker run -d -p 5000:5000 --restart=always --name registry -v /opt/myregistry:/var/lib/registry registry
docker tag docker.io/tianyebj/pod-infrastructure:latest 10.0.0.11:5000/pod-infrastructure:latest
例子从node上向主节点推。
docker push 10.0.0.11:5000/nginx:1.13
[root@k8s-master k8s]# kubectl get pod -o wide
NAME READY STATUS RESTARTS AGE IP NODE
nginx 1/1 Running 0 1m 172.16.85.2 k8s-node1
test 1/1 Running 0 18s 172.16.25.2 k8s-node2
k8s创建一个pod资源(nginx),会启动一个基础pod容器和另一个nginx容器。
docker images
docker tag docker.io/mysql:5.7 10.0.0.11:5000/mysql:5.7
docker push 10.0.0.11:5000/mysql:5.7