kubernetes常用deploy模板,并驗(yàn)證
編寫deploy配置文件
root@hello:~# cat deploy.yaml
apiVersion: Apps/v1
kind: Deployment
metadata:
name: hostname-test-cby
labels:
name: hostname-test-cby
spec:
# 副本數(shù)
replicas: 10
# 標(biāo)簽選擇器
selector:
matchLabels:
name: hostname-test-cby
# 更新策略
strategy:
rollingUpdate:
maxSurge: 3 # 更新最大數(shù)量
maxUnavailable: 3 #更新時(shí)最大不可用數(shù)量
type: RollingUpdate #滾動(dòng)更新
# 模板
template:
metadata:
labels:
name: hostname-test-cby
spec:
# 配置容器
containers:
- name: hostname-test-cby #容器名
image: Nginx #鏡像
imagePullPolicy: IfNotPresent # 拉取策略
resources:
requests:
cpu: "100m" #CPU限制
memory: "300M" #內(nèi)存限制
# 健康監(jiān)測(cè)
livenessProbe:
httpGet:
path: / # 探測(cè)路徑
port: 80 # 端口
initialDelaySeconds: 15 # 第一次探測(cè)等待
timeoutSeconds: 3 # 探測(cè)的超時(shí)后等待多少秒
# 就緒探測(cè)
readinessProbe:
httpGet:
path: / # 探測(cè)路徑
port: 80 # 端口
initialDelaySeconds: 10 # 第一次探測(cè)等待
timeoutSeconds: 3 # 探測(cè)的超時(shí)后等待多少秒
#環(huán)境變量
env:
- name: cby
value: chenby
# 配置容器端口
ports:
- containerPort: 80
# 配置掛載到目錄
volumeMounts:
- mountPath: /usr/share/nginx/html/
name: data
# 配置目錄掛載
volumes:
- name: data
hostPath:
path: /html/
type: Directory
# 配置指定解析
hostAliases:
- ip: "192.168.1.1" #IP地址
hostnames:
- "cby" #主機(jī)名
- "cby.chenby.cn" #主機(jī)名
- ip: "192.168.1.10"#IP地址
hostnames:
- "chenby" #主機(jī)名
- "chenby.chenby.cn" #主機(jī)名
root@hello:~#
執(zhí)行deploy配置文件
root@hello:~# kubectl apply -f deploy.yaml
deployment.apps/hostname-test-cby created
root@hello:~# mkdir /html
root@hello:~# echo 123 > /html/index.html
root@hello:~# kubectl get pod -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
hostname-test-cby-86df45bf-9fx5n 1/1 Running 0 43s 172.17.125.38 k8s-node01 <none> <none>
hostname-test-cby-86df45bf-cmv2b 1/1 Running 0 43s 172.17.125.37 k8s-node01 <none> <none>
hostname-test-cby-86df45bf-f6drb 1/1 Running 0 43s 172.17.125.41 k8s-node01 <none> <none>
hostname-test-cby-86df45bf-g79x2 1/1 Running 0 43s 172.27.14.232 k8s-node02 <none> <none>
hostname-test-cby-86df45bf-h6blv 1/1 Running 0 43s 172.27.14.233 k8s-node02 <none> <none>
hostname-test-cby-86df45bf-hqjnj 1/1 Running 0 43s 172.17.125.40 k8s-node01 <none> <none>
hostname-test-cby-86df45bf-jt2rz 1/1 Running 0 43s 172.27.14.236 k8s-node02 <none> <none>
hostname-test-cby-86df45bf-s5jjn 1/1 Running 0 43s 172.27.14.235 k8s-node02 <none> <none>
hostname-test-cby-86df45bf-vfkbt 1/1 Running 0 43s 172.17.125.39 k8s-node01 <none> <none>
hostname-test-cby-86df45bf-z2x2b 1/1 Running 0 43s 172.27.14.234 k8s-node02 <none> <none>
root@hello:~#
進(jìn)入pod進(jìn)行檢查
# 訪問(wèn)測(cè)試
root@hello:~# curl 172.17.125.38
123
root@hello:~#
root@hello:~# kubectl exec hostname-test-cby-86df45bf-9fx5n -it -- /bin/bash
root@hostname-test-cby-86df45bf-9fx5n:/#
# 查看DNS解析
root@hostname-test-cby-86df45bf-9fx5n:/# cat /etc/resolv.conf
search default.svc.cluster.local svc.cluster.local cluster.local
nameserver 10.96.0.10
options ndots:5
root@hostname-test-cby-86df45bf-9fx5n:/#
# 查看host配置已生效
root@hostname-test-cby-86df45bf-9fx5n:/# cat /etc/hosts
# Kubernetes-managed hosts file.
127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
fe00::0 ip6-mcastprefix
fe00::1 ip6-allnodes
fe00::2 ip6-allrouters
172.27.14.197 hostname-test-cby-86df45bf-9fx5n
# Entries added by HostAliases.
192.168.1.1 cby cby.chenby.cn
192.168.1.10 chenby chenby.chenby.cn
root@hostname-test-cby-86df45bf-9fx5n:/#
# 查看環(huán)境變量
root@hostname-test-cby-86df45bf-9fx5n:/# echo $cby
chenby
root@hostname-test-cby-86df45bf-9fx5n:/#
https://www.oiox.cn/
https://www.chenby.cn/
https://cby-chen.github.io/
https://blog.csdn.net/qq_33921750
https://my.oschina.net/u/3981543
https://www.zhihu.com/people/chen-bu-yun-2
https://segmentfault.com/u/hppyvyv6/articles
https://juejin.cn/user/3315782802482007
https://cloud.tencent.com/developer/column/93230
https://www.jianshu.com/u/0f894314ae2c
https://www.toutiao.com/c/user/token/MS4wLjABAAAAeqOrhjsoRZSj7iBJbjLJyMwYT5D0mLOgCoo4pEmpr4A/
CSDN、GitHub、知乎、開(kāi)源中國(guó)、思否、掘金、簡(jiǎn)書、騰訊云、今日頭條、個(gè)人博客、全網(wǎng)可搜《小陳運(yùn)維》
文章主要發(fā)布于微信公眾號(hào):《linux運(yùn)維交流社區(qū)》