apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: jenkins
name: ssx-jenkins-dm
namespace: ssx
spec:
replicas: 1
selector:
matchLabels:
app: jenkins
template:
metadata:
labels:
app: jenkins
spec:
containers:
- name: ssx-jenkins-c
image: node102:5000/ssx-jenkins:v1.0
ports:
- containerPort: 8080
volumeMounts:
- mountPath: /var/jenkins_home
name: c-v-path-jenkins
- mountPath: /etc/localtime
name: c-v-path-time
volumes:
- name: c-v-path-jenkins
hostPath:
path: /root/apps/k8s/for_docker_volume/jenkins
- name: c-v-path-time
hostPath:
path: /etc/localtime
nodeSelector:
kubernetes.io/hostname: node101
---
apiVersion: v1
kind: Service
metadata:
labels:
app: jenkins
name: ssx-jenkins-sv
namespace: ssx
spec:
ports:
- port: 9000
name: ssx-jenkins-last
protocol: TCP
targetPort: 8080
nodePort: 30200
selector:
app: jenkins
type: NodePort
发布后操作
- 因为jenkins脚本很大概率会执行
ssh
命令,要配置和宿主机免密登陆
执行kubectl exec xxx-jenkins-container -it /bin/bash
进入容器,然后ssh-keygen
然后ssh-copy-id 宿主机信息
完成。 - 上述步骤必须基于配置了容器挂载点,不然重启应用我们的免密信息丢失