ansible镜像构建使用

js 复制代码
cat << EOF >Dockerfile

FROM alpine:latest

RUN echo "https://mirrors.tuna.tsinghua.edu.cn/alpine/v3.18/main" > /etc/apk/repositories \
    && echo "https://mirrors.tuna.tsinghua.edu.cn/alpine/v3.18/community" >> /etc/apk/repositories \
    && apk add --no-cache ansible openssh sshpass bash-doc \
    && apk update \
    && apk add tzdata \
    && mkdir /etc/ansible \
    && echo "StrictHostKeyChecking no" > /etc/ssh/ssh_config
 
#如何你是AWS账号就要copy密钥(不是的话就忽略)
#COPY k8s.pem /opt/k8s.pem
EOF

再来一个k8s文件

js 复制代码
cat << EOF > config.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: ansible-hosts-configmap
data:
  hosts: |
    [aws]
    57.11.11.11    ansible_ssh_private_key_file=/opt/k8s.pem
    57.11.11.11    ansible_ssh_user=admin
EOF

如果你不是AWS的服务器可以跳过这里

js 复制代码
secret.yaml
apiVersion: v1
kind: Secret
metadata:
  name: k8s-prod-pem-secret
type: Opaque
data:
  k8s.pem: LS0tLS1CRUdJTiBSU0EgUFJ
  
  #转化密钥
#cat k8.pem | base64 -w 0
或者直接一条命令
shell 复制代码
kubectl create configmap k8s-prod-pem-configmap --from-file=k8s.pem -n devops-tools

不是AWS服务器使用这个yaml运行

yaml 复制代码
cat << EOF > test.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: ansible
spec:
  replicas: 1
  selector:
    matchLabels:
      app: ansible
  template:
    metadata:
      labels:
        app: ansible
    spec:
      volumes:
        - name: ansible-hosts
          configMap:
            name: ansible-hosts-configmap
        - name: k8s-prod-pem
          configMap:
            name: k8s-prod-pem-configmap
      containers:
        - name: ansible
          image: registry.cn-shenzhen.aliyuncs.com/jbjb/dockers:ansible-v01
          command: ["sleep", "3333"]
          volumeMounts:
            - name: ansible-hosts
              mountPath: /etc/ansible/hosts
              subPath: hosts
            - name: k8s-prod-pem
              mountPath: /opt/k8s.pem
              subPath: k8s.pem
              readOnly: true
EOF

AWS 服务器器使用

js 复制代码
cat << EOF > test.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: ansible
spec:
  replicas: 1
  selector:
    matchLabels:
      app: ansible
  template:
    metadata:
      labels:
        app: ansible
    spec:
      volumes:
        - name: ansible-hosts
          configMap:
            name: ansible-hosts-configmap
      containers:
        - name: ansible
          image: registry.cn-shenzhen.aliyuncs.com/jbjb/dockers:ansible-v01
          command: ["sleep", "3333"]
          volumeMounts:
            - name: ansible-hosts
              mountPath: /etc/ansible/hosts
              subPath: hosts
EOF
相关推荐
程序员老赵35 分钟前
ComfyUI Docker 镜像部署指南
人工智能·docker·aigc
biubiubiu07061 小时前
Ansible自动化
运维·自动化·ansible
会飞的土拨鼠呀1 小时前
Docker 部署开源蜜罐Cowrie
docker·容器·开源
怪我冷i1 小时前
win11使用minikube搭建K8S集群基于podman desktop( Fedora Linux 43)
linux·kubernetes·ai编程·ai写作·podman
我是谁??1 小时前
Rocky9.2离线安装docker和NVIDIA Container Toolkit训练环境搭建
运维·docker·容器
oMcLin1 小时前
如何在 Linux 上的 aaPanel 中使用 Docker 部署 WordPress 博客:从配置到上线一站式教程
linux·运维·docker
无心水2 小时前
【神经风格迁移:工程化】27、神经风格迁移全栈进阶实战:Docker容器化与K8s部署,从单机到云原生
docker·云原生·架构·神经风格迁移·docker容器化·ai部署·vgg算法
victory04312 小时前
K8S 从Harbor当中拉取镜像 连接方法
云原生·容器·kubernetes
陈陈CHENCHEN2 小时前
【Kubernetes】K8s 1.35 配置 Docker 作为容器运行时
docker·kubernetes
梁萌3 小时前
Jenkins自动化部署(docker)
docker·自动化·jenkins·流水线·cicd·smartadmin