學習轉載:https://www.jianshu.com/p/dbfe2eee3c07 node
編輯dockerfile
linux
FROM jenkins:alpine
web
MAINTAINER Ralph Wangdocker
#ENV http_proxy ${proxy_address}:${proxy_port}
api
USER root瀏覽器
# Download and config kubectl(-s:Silent or quiet mode;-O:Download; -S:Show error)app
RUN curl -L -O https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl; chmod +x ./kubectl; mv ./kubectl /usr/local/bin/kubectlcurl
# Download and config dockeride
RUN curl -O https://get.docker.com/builds/Linux/x86_64/docker-latest.tgz && tar -xvzf docker-latest.tgz; mv docker/* /usr/bin/ && rm docker-latest.tgz學習
生成鏡像
docker build -t jenkinserver:v1 .
編輯jenkins-dep.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: jenkins
labels:
app: jenkins
spec:
replicas: 1
selector:
matchLabels:
app: jenkins
template: # This is the pod template。
metadata:
labels:
app: jenkins
spec:
containers:
- name: jenkins
image: jenkinserver:v1 # Image 的名字。
imagePullPolicy: Never # 迫使 Kubernetes 使用本地鏡像。
ports:
- containerPort: 8080 # 8080 做爲 Web Console 的 Port。
name: web
protocol: TCP
- containerPort: 50000
name: agent
protocol: TCP
volumeMounts:
- mountPath: /var/run/docker.sock # 首先掛載了本地 docker 的接口,以便在 Jenkins Container 中訪問 docker。
name: docker-sock-volume
- mountPath: /var/jenkins_home # 其次掛載了 jenkins_home 以便在 Container 被摧毀是不丟失 Jenkins Server 中的內容。
name: jenkins-volume
- mountPath: /var/.kube/config # 最後掛載了外部 Kubernetes 的配置文件,以確保能夠在 Jenkins Container 內部對外部的 Kubernetes 進行修改。
name: kube-config
volumes:
- name: docker-sock-volume # Docker sock 卷。
hostPath:
path: /var/run/docker.sock
- name: jenkins-volume # Jenkins 卷。
hostPath:
path: /data/.jenkins
- name: kube-config # Kubernetes config 卷。
hostPath:
path: /data/.kube/config
部署pods
kubectl create -f jenkins-dep.yaml
編輯jesnkins-service.yaml
apiVersion: v1
kind: Service
metadata:
labels:
app: jenkins
name: jenkins
spec:
type: NodePort
ports:
- port: 8080
targetPort: 8080
nodePort: 32200 #固定訪問端口
name: web
selector:
app: jenkins
部署services
create -f jesnkins-service.yaml
問題:
一、生成鏡像時報錯Step 5/5 : RUN curl -sSL -O https://get.docker.com/builds/Linux/x86_64/docker-latest.tgz && tar -xvzf docker-latest.tgz; mv docker/* /usr/bin/ && rm docker-latest.tgz
---> Running in 1afb3f727962
curl: (56) LibreSSL SSL_read: SSL_ERROR_SYSCALL, errno 104
mv: cannot stat 'docker/*': No such file or directory
The command '/bin/sh -c curl -sSL -O https://get.docker.com/builds/Linux/x86_64/docker-latest.tgz && tar -xvzf docker-latest.tgz; mv docker/* /usr/bin/ && rm docker-latest.tgz' returned a non-zero code: 1
先將下載地址在瀏覽器測試ok,再測試去掉參數-sSL測試curl -O https://get.docker.com/builds/Linux/x86_64/docker-latest.tgz
二、部署pod查看kubectl describe pod jenkins-74b54d477f-j6gxt
發現報錯Container image is not present with pull policy of Never,原來是yaml文件中鏡像加上標識v1就正常了