Pod资源管理(pod容器分类,k8s添加harbor私库,上传下载私库)
Pod資源管理
- 了解pod
- Pod容器分類:
- 1:infrastructure container 基礎容器:維護整個Pod網絡空間
- 2:initcontainers 初始化容器
- 3:container 業務容器
- 鏡像拉取策略(image PullPolicy)
- 創建pods資源
- k8s和Harbor服務過程
- node節點配置連接私有倉庫
- 在node節點下載tomcat
- 基于本地鏡像創建tomcat
- 上傳鏡像到harbor
- 創建資源從harbor中下載鏡像
了解pod
特點:
-
最小部署單元
-
一組容器的集合
-
一個Pod中的容器共享網絡命名空間
-
Pod是短暫的
Pod容器分類:
1:infrastructure container 基礎容器:維護整個Pod網絡空間
node節點操作
查看容器的網絡
[root@localhost ~]# cat /opt/kubernetes/cfg/kubelet --pod-infra-container-image=registry.cn-hangzhou.aliyuncs.com/google-containers/pause-amd64:3.0"每次創建Pod時候就會創建,與Pod對應的,對于用戶是透明的
[root@localhost ~]# docker ps registry.cn-hangzhou.aliyuncs.com/google-containers/pause-amd64:3.0 "/pause"2:initcontainers 初始化容器
- 先于業務容器開始執行,原先Pod中容器是并行開啟,現在進行了改進
3:container 業務容器
- 并行啟動
鏡像拉取策略(image PullPolicy)
-
IfNotPresent:默認值,鏡像在宿主機上不存在時才拉取
-
Always:每次創建Pod都會重新拉取一次鏡像
-
Never:Pod永遠不會主動拉取這個鏡像
創建pods資源
[root@localhost demo]# vim pod1.yamlapiVersion: v1kind: Podmetadata:name: mypodspec:containers:- name: nginximage: nginximagePullPolicy: Alwayscommand: [ "echo", "SUCCESS" ]創建pode1
[root@localhost demo]# kubectl create -f pod1.yaml如果發生CrashLoopBackOff:失敗的狀態的原因是因為命令啟動沖突
我們刪除SUCCESS
[root@localhost demo]# kubectl get pods NAME READY STATUS RESTARTS AGE mypod 0/1 CrashLoopBackOff 2 49s //失敗的狀態的原因是因為命令啟動沖突 刪除 command: [ "echo", "SUCCESS" ]同時更改一下版本
[root@localhost ~]# vim pod1.yaml image: nginx:1.14 刪除原有的資源[root@localhost demo]# kubectl delete -f pod1.yaml pod "mypod" deleted------------------------更新資源--------------------------------[root@localhost demo]# kubectl apply -f pod1.yaml [root@localhost demo]# kubectl get podsNAME READY STATUS RESTARTS AGEmypod 1/1 Running 0 34s--------------------查看分配節點--------------------------- [root@localhost demo]# kubectl get pods -o wide NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE mypod 1/1 Running 0 118s在任意node節點使用curl 查看頭部信息
node節點操作 [root@localhost ~]# curl -I 172.17.31.6 HTTP/1.1 200 OK Server: nginx/1.14.2k8s和Harbor服務過程
重新開啟一個node節點
以下服務都是在有docker的前提下部署的!!!
安裝docker-compose
系統可以識別
mv docker-compose /usr/local/bin/ 1查看是否安裝
[root@localhost ~]# docker-compose -v docker-compose version 1.21.1, build 5a3f1a3 12安裝harbor
[root@localhost ~]# tar zxvf harbor-offline-installer-v1.2.2.tgz -C /usr/local/ 1修改配置文件
[root@localhost ~]# cd /usr/local/harbor/ [root@localhost harbor]# vim harbor.cfg 5 hostname = 192.168.136.81 123開啟Harbor
[root@localhost harbor]# sh install.sh 1輸入地址查看
密碼Harbor12345默認
node節點配置連接私有倉庫
2個node節點都要配置
(注意后面的逗號要添加)
[root@localhost ~]# vim /etc/docker/daemon.json {"registry-mirrors": ["https://05vz3np5.mirror.aliyuncs.com"],"insecure-registries":["192.168.136.50"] }開啟服務
[root@localhost ~]# systemctl restart docker登錄harbor私有倉庫
[root@localhost ~]# docker login 192.168.136.50Username: admin Password: //輸入密碼Harbor12345查看憑證文件
[root@localhost ~]# ls -a .docker [root@localhost ~]# cd .docker/ (查看憑證) [root@localhost .docker]# cat config.json | base64 -w 0 ewoJImF1dGhzIjogewoJCSIxOTIuMTY4LjEzNi41MCI6IHsKCQkJImF1dGgiOiAiWVdSdGFXNDZTR0Z5WW05eU1USXpORFU9IgoJCX0KCX0sCgkiSHR0cEhlYWRlcnMiOiB7CgkJIlVzZXItQWdlbnQiOiAiRG9ja2VyLUNsaWVudC8xOS4wMy4xMyAobGludXgpIgoJfQp9[root@localhost .docker]#-w 0 禁用轉行
在node節點下載tomcat
下載Tomcat鏡像進行推送
[root@localhost ~]# docker pull tomcat [root@localhost ~]# docker images 查看tomcatweb復制推送鏡像
打標簽
復制粘貼到node節點
[root@localhost ~]# docker tag tomcat 192.168.136.50/project/tomcat推送成功
[root@localhost ~]# docker tag tomcat 192.168.136.50/project/tomcat查看web游覽器
基于本地鏡像創建tomcat
在matser節點下載tomcat鏡像
[root@localhost demo]# vim tomcat-deployment.yaml apiVersion: extensions/v1beta1 kind: Deployment metadata:name: my-tomcat spec:replicas: 2template:metadata:labels:app: my-tomcatspec:containers:- name: my-tomcatimage: docker.io/tomcat:8.0.52ports:- containerPort: 80 --- apiVersion: v1 kind: Service metadata:name: my-tomcat spec:type: NodePortports:- port: 8080targetPort: 8080nodePort: 31111selector:app: my-tomcatnode節點部署tomcat
[root@localhost ~]# docker pull tomcat:8.0.52在master上發布服務
[root@localhost demo]# kubectl apply -f tomcat-deployment.yaml查看端口
nginx-service NodePort 10.0.0.193 <none> 80:41108/TCP 68m [root@localhost ~]# kubectl get pods -o wide NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE my-tomcat-7cd4fdbb5b-8b6bx 1/1 Running 0 3m1s 172.17.38.5 192.168.136.40 <none> my-tomcat-7cd4fdbb5b-ss8nc 1/1 Running 0 3m1s 172.17.27.4 192.168.136.30 <none>查看tomcat服務端口號
[root@localhost ~]# kubectl get svc NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE kubernetes ClusterIP 10.0.0.1 <none> 443/TCP 4d13h my-tomcat NodePort 10.0.0.216 <none> 8080:31111/TCP 71m游覽器192.168.136.40:31111
如果遇到處于Terminating狀態的無法刪除的資源如何處理
[root@localhost demo]# kubectl get podsNAME READY STATUS RESTARTS AGEmy-tomcat-57667b9d9-nklvj 1/1 Terminating 0 10hmy-tomcat-57667b9d9-wllnp 1/1 Terminating 0 10h//這種情況下可以使用強制刪除命令: kubectl delete pod [pod name] --force --grace-period=0 -n [namespace]上傳鏡像到harbor
node01上操作(之前登陸過harbor倉庫的節點)
鏡像打標簽
[root@localhost ~]# docker tag tomcat:8.0.52 192.168.136.50/project/tomcat刪除之前的鏡像
上傳鏡像到harbor
[root@localhost ~]# docker push 192.168.136.50/project/tomcat8查看登陸憑據
[root@localhost ~]# cat .docker/config.json |base64 -w 0 ewoJImF1dGhzIjogewoJCSIxOTIuMTY4LjEzNi41MCI6IHsKCQkJImF1dGgiOiAiWVdSdGFXNDZTR0Z5WW05eU1USXpORFU9IgoJCX0KCX0sCgkiSHR0cEhlYWRlcnMiOiB7CgkJIlVzZXItQWdlbnQiOiAiRG9ja2VyLUNsaWVudC8xOS4wMy4xMyAobGludXgpIgoJfQp9master節點創建
[root@localhost demo]# vim registry-pull-secret.yaml apiVersion: v1 kind: Secret metadata:name: registry-pull-secret data:.dockerconfigjson:ewoJImF1dGhzIjogewoJCSIxOTIuMTY4LjEzNi41MCI6IHsKCQkJImF1dGgiOiAiWVdSdGFXNDZTR0Z5WW05eU1USXpORFU9IgoJCX0KCX0sCgkiSHR0cEhlYWRlcnMiOiB7CgkJIlVzZXItQWdlbnQiOiAiRG9ja2VyLUNsaWVudC8xOS4wMy4xMyAobGludXgpIgoJfQp9 type: kubernetes.io/dockerconfigjson創建secret資源
[root@localhost ~]# kubectl create -f registry-pull-secret.yaml查看secret資源
[root@localhost ~]# kubectl get secret NAME TYPE DATA AGE default-token-w6xph kubernetes.io/service-account-token 3 4d22h registry-pull-secret kubernetes.io/dockerconfigjson 1 40s創建資源從harbor中下載鏡像
[root@localhost ~]# kubectl create -f registry-pull-secret.yaml 刪除原有的鏡像 [root@localhost demo]# vim tomcat-deployment.yaml spec:imagePullSecrets: 下面添加- name: registry-pull-secret containers:image: 192.168.195.80/project/tomcat ports:創建資源
kubectl create -f tomcat-deployment.yaml私有倉庫中的鏡像被下載了2次
超強干貨來襲 云風專訪:近40年碼齡,通宵達旦的技術人生總結
以上是生活随笔為你收集整理的Pod资源管理(pod容器分类,k8s添加harbor私库,上传下载私库)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 傲腾内存,轻松应对,速度与容量双保障
- 下一篇: 内存超频:为何不可行?